Skip to content

Commit 0fb5ee2

Browse files
committed
regcomp_invlist.c: Perl_populate_bitmap_from_invlist() optimize asserts()
Inside re.xs/re.dll, Perl_populate_bitmap_from_invlist() has half a dozen if(!invlist) _assert_libc() call sites. Atleast PERL_ARGS_ASSERT_POPULATE_BITMAP_FROM_INVLIST, invlist_iterinit(), invlist_iternext(), invlist_iterfinish() are all testing a C auto var that was proven inside PERL_ARGS_ASSERT_POPULATE_BITMAP_FROM_INVLIST to be true. "SV * invlist" is a C auto and I don't belive it is "reachable" under ISO C. Perl_populate_bitmap_from_invlist() never does & operator on it. But atleast MSVC 2022 is constantly re-reading this C auto. Also Perl_populate_bitmap_from_invlist() has only 1 call site, and MSVC hoisted/folded/inlined away "const Size_t len" since its always 8. #define REGNODE_BBM_BITMAP_LEN /* 6 info bits requires 64 bits; 5 => 32 */ ((1 << (UTF_CONTINUATION_BYTE_INFO_BITS)) / CHARBITS) since MSVC doesnt inline memcpy symbol func calls b/c WinPerl doesnt request it, make it obvious here to skip the libc call on all platforms.
1 parent 8c71d4a commit 0fb5ee2

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

regcomp_invlist.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,19 @@ void
2323
Perl_populate_bitmap_from_invlist(pTHX_ SV * invlist, const UV offset, const U8 * bitmap, const Size_t len)
2424
{
2525
PERL_ARGS_ASSERT_POPULATE_BITMAP_FROM_INVLIST;
26+
ASSUME(invlist && bitmap);
2627

2728
/* As the name says. The zeroth bit corresponds to the code point given by
2829
* 'offset' */
2930

3031
UV start, end;
3132

32-
Zero(bitmap, len, U8);
33+
if (len == sizeof(U64)
34+
&& ( ((STRUCT_OFFSET(struct regnode_bbm, bitmap) % 8) == 0)
35+
|| (PTR2nat(bitmap) & 0x7) == 0))
36+
*(U64*)bitmap = 0;
37+
else
38+
Zero(bitmap, len, U8);
3339

3440
invlist_iterinit(invlist);
3541
while (invlist_iternext(invlist, &start, &end)) {

0 commit comments

Comments
 (0)