groff
[Top][All Lists]
Advanced

[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




reply via email to

[Prev in Thread] Current Thread [Next in Thread]