summaryrefslogtreecommitdiff
path: root/embed.fnc
diff options
context:
space:
mode:
authorKarl Williamson <khw@cpan.org>2020-10-16 13:27:55 -0600
committerKarl Williamson <khw@cpan.org>2020-10-31 11:04:19 -0600
commitcc448ceab170493a35039184f4f85054a8ddf971 (patch)
tree23ad961bdeae2eb6fe5b5bc4d8be4494d9a1d180 /embed.fnc
parentf30cbf5aa3835c9fb81f5212c3c56439f940ae19 (diff)
downloadperl-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 'embed.fnc')
-rw-r--r--embed.fnc5
1 files changed, 3 insertions, 2 deletions
diff --git a/embed.fnc b/embed.fnc
index be253fe72f..e088cd844c 100644
--- a/embed.fnc
+++ b/embed.fnc
@@ -753,8 +753,9 @@ Ap |I32 |debop |NN const OP* o
Ap |I32 |debstack
Ap |I32 |debstackptrs
pR |SV * |defelem_target |NN SV *sv|NULLOK MAGIC *mg
-ATp |char* |delimcpy |NN char* to|NN const char* toend|NN const char* from \
- |NN const char* fromend|int delim|NN I32* retlen
+ATpd |char* |delimcpy|NN char* to|NN const char* to_end \
+ |NN const char* from|NN const char* from_end \
+ |const int delim|NN I32* retlen
Tpd |char* |delimcpy_no_escape|NN char* to|NN const char* toend \
|NN const char* from \
|NN const char* fromend|int delim \