diff options
author | Karl Williamson <khw@cpan.org> | 2020-10-16 13:27:55 -0600 |
---|---|---|
committer | Karl Williamson <khw@cpan.org> | 2020-10-31 11:04:19 -0600 |
commit | cc448ceab170493a35039184f4f85054a8ddf971 (patch) | |
tree | 23ad961bdeae2eb6fe5b5bc4d8be4494d9a1d180 /proto.h | |
parent | f30cbf5aa3835c9fb81f5212c3c56439f940ae19 (diff) | |
download | perl-cc448ceab170493a35039184f4f85054a8ddf971.tar.gz |
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.
Diffstat (limited to 'proto.h')
-rw-r--r-- | proto.h | 4 |
1 files changed, 2 insertions, 2 deletions
@@ -837,9 +837,9 @@ PERL_CALLCONV SV * Perl_defelem_target(pTHX_ SV *sv, MAGIC *mg) PERL_CALLCONV void Perl_delete_eval_scope(pTHX); #define PERL_ARGS_ASSERT_DELETE_EVAL_SCOPE -PERL_CALLCONV char* Perl_delimcpy(char* to, const char* toend, const char* from, const char* fromend, int delim, I32* retlen); +PERL_CALLCONV char* Perl_delimcpy(char* to, const char* to_end, const char* from, const char* from_end, const int delim, I32* retlen); #define PERL_ARGS_ASSERT_DELIMCPY \ - assert(to); assert(toend); assert(from); assert(fromend); assert(retlen) + assert(to); assert(to_end); assert(from); assert(from_end); assert(retlen) PERL_CALLCONV char* Perl_delimcpy_no_escape(char* to, const char* toend, const char* from, const char* fromend, int delim, I32* retlen); #define PERL_ARGS_ASSERT_DELIMCPY_NO_ESCAPE \ assert(to); assert(toend); assert(from); assert(fromend); assert(retlen) |