This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Rewrite delimcpy to use memchr and Copy, not per-byte
authorKarl Williamson <khw@cpan.org>
Fri, 16 Oct 2020 19:27:55 +0000 (13:27 -0600)
committerKarl Williamson <khw@cpan.org>
Sat, 31 Oct 2020 17:04:19 +0000 (11:04 -0600)
commitcc448ceab170493a35039184f4f85054a8ddf971
tree23ad961bdeae2eb6fe5b5bc4d8be4494d9a1d180
parentf30cbf5aa3835c9fb81f5212c3c56439f940ae19
Rewrite delimcpy to use memchr and Copy, not per-byte

Prior to this commit delimcpy() parsed its input byte-by-byte, looking
for a particular character, and copied the input to the output stopping
just before the first such occurrence.

memchr() is much faster for finding a single character.

The complication is that if the character is preceded by a backslash,
it doesn't count as that character, it is considered to be escaped, and
parsing continues to the first unescaped occurrence, if any. Each
escaping backslash is not copied.

The prior code also failed to account for the possibility of the delimiter
being a backslash, the same as the escape.

The new routine looks for the character with memchr, sees if it is
escaped. If not, Copy does the whole copy at once. If it is escaped,
it uses Copy up to that backslash, and repeats the process.
embed.fnc
ext/XS-APItest/t/delimcpy.t
proto.h
util.c