Branch: refs/heads/davem/simplify_make_trie
  Home:   https://github.com/Perl/perl5
  Commit: f7c9d55bf7282c4d4cc155a4a3084ae328f19a96
      
https://github.com/Perl/perl5/commit/f7c9d55bf7282c4d4cc155a4a3084ae328f19a96
  Author: David Mitchell <da...@iabyn.com>
  Date:   2024-04-01 (Mon, 01 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: d3ddc7c49dd025aab0bfcdc741dbfa6d0a71535e
      
https://github.com/Perl/perl5/commit/d3ddc7c49dd025aab0bfcdc741dbfa6d0a71535e
  Author: David Mitchell <da...@iabyn.com>
  Date:   2024-04-01 (Mon, 01 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/f7c9d55bf728%5E...d3ddc7c49dd0

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

Reply via email to