Re: [PATCH] Optimize split //
Ævar Arnfjörð Bjarmason [Sat, 11 Aug 2007 20:33:49 +0000 (20:33 +0000)]
From: Ã\86var Arnfjörð Bjarmason <avarab@gmail.com>
Message-Id: <51dd1af80708111333kfd82e12u145b5ba38e23dcce@mail.gmail.com>

p4raw-id: //depot/perl@31704

pp.c

diff --git a/pp.c b/pp.c
index 02e530f..54df53e 100644 (file)
--- a/pp.c
+++ b/pp.c
@@ -4726,26 +4726,36 @@ PP(pp_split)
         else
             EXTEND(SP, slen);
 
-        while (--limit) {
-            m = s;
-            
-            if (do_utf8)
+        if (do_utf8) {
+            while (--limit) {
+                /* keep track of how many bytes we skip over */
+                m = s;
                 s += UTF8SKIP(s);
-            else
-                ++s;
+                dstr = newSVpvn(m, s-m);
 
-            dstr = newSVpvn(m, s-m);
+                if (make_mortal)
+                    sv_2mortal(dstr);
 
-            if (make_mortal)
-                sv_2mortal(dstr);
-            if (do_utf8)
                 (void)SvUTF8_on(dstr);
+                PUSHs(dstr);
 
-            PUSHs(dstr);
+                if (s >= strend)
+                    break;
+            }
+        } else {
+            while (--limit) {
+                dstr = newSVpvn(s, 1);
+
+                s++;
+
+                if (make_mortal)
+                    sv_2mortal(dstr);
 
-            /* are we there yet? */
-            if (s >= strend)
-                break;
+                PUSHs(dstr);
+
+                if (s >= strend)
+                    break;
+            }
         }
     }
     else if (do_utf8 == ((rx->extflags & RXf_UTF8) != 0) &&