diff options
author | Hugo van der Sanden <hv@crypt.org> | 2003-01-21 01:37:03 +0000 |
---|---|---|
committer | hv <hv@crypt.org> | 2003-01-21 01:37:03 +0000 |
commit | 7e8c5daceba7cb185532328a3b67d4ca7ba4811b (patch) | |
tree | 6fbcb357ec74beb075b5c99dbc3f3ac52e68114f /mg.c | |
parent | 388cc4de5f48b02cc9fe9b962f02cf603af02178 (diff) | |
download | perl-7e8c5daceba7cb185532328a3b67d4ca7ba4811b.tar.gz |
integrate (by hand) #18353 and #18359 from maint-5.8:
Introduce a cache for UTF-8 data: length and byte<->char offset
mapping are stored in a new type of magic. Speeds up length(),
substr(), index(), rindex(), pos(), and some parts of s///.
The speedup varies a lot (on the usual suspects: what is the
access pattern of the data, compiler, CPU), but should be at
least one order of magnitude, and getting to the same magnitude
as byte string speeds, and in some cases (length on unchanged data)
even reaching the byte string speed. On the other hand, in some
cases (index) the byte speed is still faster by a factor of five
or so, but the bottleneck there does not seem to be any more
the byte<->char offset mapping (instead, the fbm_instr() speed).
There is one cache slot for the length, and only two for the
byte<->char offset mapping (the first one for the start->offset,
and the second for the offset->offset+length, when talking
in substr() terms).
Code this hairy is bound to have hairy trolls hiding under it.
[...]
A small tweak on top of #18353: don't display mg_len bytes of
mg_ptr for PERL_MAGIC_utf8 because that's not what's there.
p4raw-id: //depot/perl@18530
Diffstat (limited to 'mg.c')
-rw-r--r-- | mg.c | 10 |
1 files changed, 10 insertions, 0 deletions
@@ -1835,6 +1835,16 @@ Perl_magic_setcollxfrm(pTHX_ SV *sv, MAGIC *mg) } #endif /* USE_LOCALE_COLLATE */ +/* Just clear the UTF-8 cache data. */ +int +Perl_magic_setutf8(pTHX_ SV *sv, MAGIC *mg) +{ + Safefree(mg->mg_ptr); /* The mg_ptr holds the pos cache. */ + mg->mg_ptr = 0; + mg->mg_len = -1; /* The mg_len holds the len cache. */ + return 0; +} + int Perl_magic_set(pTHX_ SV *sv, MAGIC *mg) { |