[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v1 2/2] [troff]: Rewrite function in C.
From: |
Alejandro Colomar |
Subject: |
[PATCH v1 2/2] [troff]: Rewrite function in C. |
Date: |
Fri, 4 Aug 2023 03:00:12 +0200 |
* src/roff/troff/env.cpp (is_family_valid): The old code was
eyeball-bleeding. This cuts 6 lines to 3, and each of them is
significantly simpler to read. Remove the comments of how it could
be improved using modern C++, as I don't think it would improve much
vs this C implementation.
Signed-off-by: Alejandro Colomar <alx@kernel.org>
---
I need a new pair of eyeballs. They bleeded so much!
src/roff/troff/env.cpp | 12 ++++--------
1 file changed, 4 insertions(+), 8 deletions(-)
diff --git a/src/roff/troff/env.cpp b/src/roff/troff/env.cpp
index 106ab6889..23d81275a 100644
--- a/src/roff/troff/env.cpp
+++ b/src/roff/troff/env.cpp
@@ -1260,14 +1260,10 @@ void font_change()
bool is_family_valid(const char *fam)
{
- // std::vector<const char *> styles{"R", "I", "B", "BI"}; // C++11
- const size_t nstyles = 4;
- const char *st[nstyles] = { "R", "I", "B", "BI" };
- std::vector<const char *> styles(st, (st + nstyles));
- // for (auto style : styles) // C++11
- std::vector<const char *>::iterator style;
- for (style = styles.begin(); style != styles.end(); style++)
- if (!check_font(fam, *style))
+ static const char styles[][3] = { "R", "I", "B", "BI" };
+
+ for (size_t i = 0; i < lengthof(styles); i++)
+ if (!check_font(fam, styles[i]))
return false;
return true;
}
--
2.40.1
- [PATCH v1 1/2] [troff]: Add lengthof() macro., Alejandro Colomar, 2023/08/03
- [PATCH v1 2/2] [troff]: Rewrite function in C.,
Alejandro Colomar <=
- Re: [PATCH v1 2/2] [troff]: Rewrite function in C., Alejandro Colomar, 2023/08/03
- Re: [PATCH v1 1/2] [troff]: Add lengthof() macro., G. Branden Robinson, 2023/08/04
- Re: [PATCH v1 1/2] [troff]: Add lengthof() macro., Alejandro Colomar, 2023/08/04
- Re: [PATCH v1 1/2] [troff]: Add lengthof() macro., James K. Lowden, 2023/08/07
- Re: [PATCH v1 1/2] [troff]: Add lengthof() macro., G. Branden Robinson, 2023/08/25
- Re: [PATCH v1 1/2] [troff]: Add lengthof() macro., Alejandro Colomar, 2023/08/25
- Re: [PATCH v1 1/2] [troff]: Add lengthof() macro., G. Branden Robinson, 2023/08/26
- Re: [PATCH v1 1/2] [troff]: Add lengthof() macro., Lennart Jablonka, 2023/08/26
- Re: [PATCH v1 1/2] [troff]: Add lengthof() macro., Alejandro Colomar, 2023/08/26
- Re: [PATCH v1 1/2] [troff]: Add lengthof() macro., Alejandro Colomar, 2023/08/26