groff
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH v1 2/2] [troff]: Rewrite function in C.


From: Alejandro Colomar
Subject: Re: [PATCH v1 2/2] [troff]: Rewrite function in C.
Date: Fri, 4 Aug 2023 03:05:01 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.13.1

On 2023-08-04 03:00, Alejandro Colomar wrote:
> *  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>
> ---

Disclaimer: I did a build, but didn't really try it.

> 
> 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;
>  }

-- 
<http://www.alejandro-colomar.es/>
GPG key fingerprint: A9348594CE31283A826FBDD8D57633D441E25BB5

Attachment: OpenPGP_signature
Description: OpenPGP digital signature


reply via email to

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