This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
sv.c:sv_pos_u2b: Don’t cache anything on magical SVs
authorFather Chrysostomos <sprout@cpan.org>
Fri, 28 Sep 2012 13:16:55 +0000 (06:16 -0700)
committerFather Chrysostomos <sprout@cpan.org>
Mon, 1 Oct 2012 19:51:54 +0000 (12:51 -0700)
This should not change the behaviour.  It is just unnecessary to cache
positions on a magical string, as we then just have to invalidate the
cache in mg_get.  It will be more efficient just not to create the
cache to begin with.

This does not allow us to remove the cache invalidation in mg_get,
because the cache can sometimes be created while magic is being called
and SvMAGICAL is off.  It just avoids extra work in those cases that
are detectable.

sv.c

diff --git a/sv.c b/sv.c
index ee0f755..041cfaf 100644 (file)
--- a/sv.c
+++ b/sv.c
@@ -6642,7 +6642,7 @@ S_sv_pos_u2b_cached(pTHX_ SV *const sv, MAGIC **const mgp, const U8 *const start
     if (!uoffset)
        return 0;
 
-    if (!SvREADONLY(sv)
+    if (!SvREADONLY(sv) && !SvGMAGICAL(sv)
        && PL_utf8cache
        && (*mgp || (SvTYPE(sv) >= SVt_PVMG &&
                     (*mgp = mg_find(sv, PERL_MAGIC_utf8))))) {
@@ -6725,7 +6725,7 @@ S_sv_pos_u2b_cached(pTHX_ SV *const sv, MAGIC **const mgp, const U8 *const start
        boffset = real_boffset;
     }
 
-    if (PL_utf8cache) {
+    if (PL_utf8cache && !SvGMAGICAL(sv)) {
        if (at_end)
            utf8_mg_len_cache_update(sv, mgp, uoffset);
        else