Branch: refs/heads/blead
  Home:   https://github.com/Perl/perl5
  Commit: 336ff86118129713ab83e0ed3654a3836d6f3078
      
https://github.com/Perl/perl5/commit/336ff86118129713ab83e0ed3654a3836d6f3078
  Author: David Mitchell <da...@iabyn.com>
  Date:   2024-04-02 (Tue, 02 Apr 2024)

  Changed paths:
    M regcomp_trie.c

  Log Message:
  -----------
  make TRIE_BITMAP_SET_FOLDED macro into a function

This is a private macro used just in regcomp_trie.c. It uses lots of
macros itself, so locating problems quickly leads to Macro Hell. So this
commit converts it into a static (but *not* inline) function.


  Commit: 589e2b8538d6d149efcec73ddddb7d1dd78c59c4
      
https://github.com/Perl/perl5/commit/589e2b8538d6d149efcec73ddddb7d1dd78c59c4
  Author: David Mitchell <da...@iabyn.com>
  Date:   2024-04-02 (Tue, 02 Apr 2024)

  Changed paths:
    M regcomp_trie.c

  Log Message:
  -----------
  Slightly optimise S_trie_bitmap_set_folded()

This static function in regcomp_trie.c evaluates UTF8_TWO_BYTE_HI(uvc)
twice, because a macro it calls uses the passed expression twice.
So calculate the value once into a local var.

Now, the compiler might already optimise this. But this commit may
or may not also have the (hoped for) side effect of shutting up a
Coverity warning.

The code is taking an 8-bit variant char, calculating what its upper
byte would be if converted to utf-8 (so in this case, only 0xc2 and 0xc3
are possible), then setting a bit in a trie representing this value. The
bit setting involves calculating the byte and bit offsets - the former
by doing >>3. But doing that shift on c2/c3 always gives the same
value, so Coverity is rightfully warning that UTF8_TWO_BYTE_HI(uvc) >> 3
is always constant.

By splitting that expression into two statements, maybe Coverity won't
notice. If it still does, at least this commit simplifies the code and
will make any eventual fix easier.

Here's the original Coverity report (it's complaining about the macro
which the previous commit subsequently turned into a static function):

>>>     CID 488118:    (CONSTANT_EXPRESSION_RESULT)
>>>     "(UV)(U8)(((UV)(*ch | 0) >> 6) | 192UL /* (U8)~(0xff >> 2) */) >> 3" is
0x18 regardless of the values of its operands. This occurs as a value.
1403                                         TRIE_BITMAP_SET_FOLDED(trie,*ch, 
folder);


Compare: https://github.com/Perl/perl5/compare/0fff722e99f3...589e2b8538d6

To unsubscribe from these emails, change your notification settings at 
https://github.com/Perl/perl5/settings/notifications

Reply via email to