<<< Date Index >>>     <<< Thread Index >>>

Re: Few warnings in cvs



Hi,

* Vincent Lefevre [06-11-17 08:42:34 +0100] wrote:
On 2006-11-14 20:52:56 +0000, Rocco Rutte wrote:
Yes. Maybe it's some legacy code or something where somebody used 'unsigned char' instead of uint8_t.

Why not int? Here c1 is nothing more than an array index:

                   c1 = 0;

                   /* If pattern is `[[:'.  */
                   if (p == pend) FREE_STACK_RETURN (REG_EBRACK);

                   for (;;)
                     {
                       PATFETCH (c);
                       if (c == ':' || c == ']' || p == pend
                           || c1 == CHAR_CLASS_MAX_LENGTH)
                         break;
                       str[c1++] = c;
                     }
                   str[c1] = '\0';

Int is simply too large with its 4 bytes. uint8_t is supposed to be 1 byte only... and when CHAR_CLASS_MAX_LENGTH is 255, this is sufficient. And sizeof(char) is usually 1 (byte), too.

Also as it seems, the c1 variable is reused deeply within the code (also as a real char) so declaring it once for many cases also saves a little memory and/or moving the stack pointer.

If you cleverly place a uint8_t with some more of these smaller parameters, it may save a few bytes memory since the compiler can internally pack them into just one int (like it does for all the bit fields mutt uses for its structures).

Of course, we could now start fixing regex.c, but it's not mutt (native) code and only provided as fallback in case people have no working regex in their libc. And thus I don't think it's worth it to tune/beautify regex.c.

  bye, Rocco
--
:wq!