Change 27578 by [EMAIL PROTECTED] on 2006/03/23 10:42:26

        Use the cache in S_sv_pos_u2b_cached when the sought offset is after
        the first cache entry.

Affected files ...

... //depot/perl/sv.c#1203 edit

Differences ...

==== //depot/perl/sv.c#1203 (text) ====
Index: perl/sv.c
--- perl/sv.c#1202~27577~       2006-03-23 02:01:48.000000000 -0800
+++ perl/sv.c   2006-03-23 02:42:26.000000000 -0800
@@ -5559,7 +5559,34 @@
 
     if (SvMAGICAL(sv) && !SvREADONLY(sv) && PL_utf8cache
        && (*mgp || (*mgp = mg_find(sv, PERL_MAGIC_utf8)))) {
-       if ((*mgp)->mg_len != -1) {
+       if ((*mgp)->mg_ptr) {
+           STRLEN *cache = (STRLEN *) (*mgp)->mg_ptr;
+           if (cache[0] == uoffset) {
+               /* An exact match. */
+               return cache[1];
+           }
+           else if (cache[0] < uoffset) {
+               /* The cache already knows part of the way.   */
+               if (cache[0] > uoffset0) {
+                   /* The cache knows more than the passed in pair  */
+                   uoffset0 = cache[0];
+                   boffset0 = cache[1];
+               }
+               if ((*mgp)->mg_len != -1) {
+                   /* And we know the end too.  */
+                   boffset = boffset0
+                       + S_sv_pos_u2b_midway(aTHX_ start + boffset0, send,
+                                             uoffset - uoffset0,
+                                             (*mgp)->mg_len - uoffset0);
+               } else {
+                   boffset = boffset0
+                       + S_sv_pos_u2b_forwards(aTHX_ start + boffset0,
+                                               send, uoffset - uoffset0);
+               }
+               found = TRUE;
+           }
+       }
+       else if ((*mgp)->mg_len != -1) {
            /* If we can take advantage of a passed in offset, do so.  */
            /* In fact, offset0 is either 0, or less than offset, so don't
               need to worry about the other possibility.  */
End of Patch.

Reply via email to