This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Add regnode LEXACT, for long strings
authorKarl Williamson <khw@cpan.org>
Wed, 25 Sep 2019 16:12:32 +0000 (10:12 -0600)
committerKarl Williamson <khw@cpan.org>
Sun, 29 Sep 2019 17:46:26 +0000 (11:46 -0600)
commitae06e581c6e9944620eed4980fe89a3749886ed0
tree44d0e3585bccc343af3dab4ceb693667aafe1b90
parent3ae8ec479bc65ef004bd856d90b82106186771d9
Add regnode LEXACT, for long strings

This commit adds a new regnode for strings that don't fit in a regular
one, and adds a structure for that regnode to use.  Actually using them
is deferred to the next commit.

This new regnode structure is needed because the previous structure only
allows for an 8 bit length field, 255 max bytes.  This commit puts the
length instead in a new field, the same place single-argument regnodes
put their argument.  Hence this long string is an extra 32 bits of
overhead, but at no string length is this node ever bigger than the
combination of the smaller nodes it replaces.

I also considered simply combining the original 8 bit length field
(which is now unused) with the first byte of the string field to get a
16 bit length, and have the actual string be offset by 1.  But I
rejected that because it would mean the string would usually not be
aligned, slowing down memory accesses.

This new LEXACT regnode can hold up to what 1024 regular EXACT ones hold,
using 4K fewer overhead bytes to do so.  That means it can handle
strings containing 262000 bytes.  The comments give ideas for expanding
that should it become necessary or desirable.

Besides the space advantage, any hardware acceleration in memcmp
can be done in much bigger chunks, and otherwise the memcmp inner loop
(often written in assembly) will run many more times in a row, and our
outer loop that calls it, correspondingly fewer.
pod/perldebguts.pod
regcomp.h
regcomp.sym
regexec.c
regnodes.h