This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
In S_sv_pos_u2b_midway, inline the call to S_sv_pos_u2b_forwards.
authorNicholas Clark <nick@ccl4.org>
Sun, 11 Jul 2010 15:49:29 +0000 (16:49 +0100)
committerNicholas Clark <nick@ccl4.org>
Sun, 11 Jul 2010 15:49:29 +0000 (16:49 +0100)
embed.fnc
proto.h
sv.c

index 1ba9041..4b04803 100644 (file)
--- a/embed.fnc
+++ b/embed.fnc
@@ -1885,7 +1885,7 @@ sR        |I32    |expect_number  |NN char **const pattern
 sn     |STRLEN |sv_pos_u2b_forwards|NN const U8 *const start \
                |NN const U8 *const send|STRLEN uoffset
 sn     |STRLEN |sv_pos_u2b_midway|NN const U8 *const start \
-               |NN const U8 *send|const STRLEN uoffset|const STRLEN uend
+               |NN const U8 *send|STRLEN uoffset|const STRLEN uend
 s      |STRLEN |sv_pos_u2b_cached|NN SV *const sv|NN MAGIC **const mgp \
                |NN const U8 *const start|NN const U8 *const send \
                |const STRLEN uoffset|STRLEN uoffset0|STRLEN boffset0
diff --git a/proto.h b/proto.h
index f25b40c..86658c1 100644 (file)
--- a/proto.h
+++ b/proto.h
@@ -5815,7 +5815,7 @@ STATIC STRLEN     S_sv_pos_u2b_forwards(const U8 *const start, const U8 *const send,
 #define PERL_ARGS_ASSERT_SV_POS_U2B_FORWARDS   \
        assert(start); assert(send)
 
-STATIC STRLEN  S_sv_pos_u2b_midway(const U8 *const start, const U8 *send, const STRLEN uoffset, const STRLEN uend)
+STATIC STRLEN  S_sv_pos_u2b_midway(const U8 *const start, const U8 *send, STRLEN uoffset, const STRLEN uend)
                        __attribute__nonnull__(1)
                        __attribute__nonnull__(2);
 #define PERL_ARGS_ASSERT_SV_POS_U2B_MIDWAY     \
diff --git a/sv.c b/sv.c
index c38a318..45a9894 100644 (file)
--- a/sv.c
+++ b/sv.c
@@ -6110,7 +6110,7 @@ S_sv_pos_u2b_forwards(const U8 *const start, const U8 *const send,
    the passed in UTF-8 offset.  */
 static STRLEN
 S_sv_pos_u2b_midway(const U8 *const start, const U8 *send,
-                     const STRLEN uoffset, const STRLEN uend)
+                   STRLEN uoffset, const STRLEN uend)
 {
     STRLEN backw = uend - uoffset;
 
@@ -6120,7 +6120,14 @@ S_sv_pos_u2b_midway(const U8 *const start, const U8 *send,
        /* The assumption is that going forwards is twice the speed of going
           forward (that's where the 2 * backw comes from).
           (The real figure of course depends on the UTF-8 data.)  */
-       return sv_pos_u2b_forwards(start, send, uoffset);
+       const U8 *s = start;
+
+       while (s < send && uoffset--)
+           s += UTF8SKIP(s);
+       assert (s <= send);
+       if (s > send)
+           s = send;
+       return s - start;
     }
 
     while (backw--) {