Change 33377 by [EMAIL PROTECTED] on 2008/02/26 19:17:38

        If we have malloced_size() available, then avoid rounding up the string
        to the next (guessed) plausible alignment size, and instead find out
        how much memory was actually allocated, so that we can set this in the
        scalar's SvLEN(). This way, sv_grow() will be called far less often.

Affected files ...

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

Differences ...

==== //depot/perl/sv.c#1510 (text) ====
Index: perl/sv.c
--- perl/sv.c#1509~33342~       2008-02-21 16:07:15.000000000 -0800
+++ perl/sv.c   2008-02-26 11:17:38.000000000 -0800
@@ -1479,15 +1479,10 @@
        s = SvPVX_mutable(sv);
 
     if (newlen > SvLEN(sv)) {          /* need more room? */
+#ifndef MYMALLOC
        newlen = PERL_STRLEN_ROUNDUP(newlen);
-       if (SvLEN(sv) && s) {
-#ifdef MYMALLOC
-           const STRLEN l = malloced_size((void*)SvPVX_const(sv));
-           if (newlen <= l) {
-               SvLEN_set(sv, l);
-               return s;
-           } else
 #endif
+       if (SvLEN(sv) && s) {
            s = (char*)saferealloc(s, newlen);
        }
        else {
@@ -1497,7 +1492,14 @@
            }
        }
        SvPV_set(sv, s);
+#ifdef MYMALLOC
+       /* Do this here, do it once, do it right, and then we will never get
+          called back into sv_grow() unless there really is some growing
+          needed.  */
+       SvLEN_set(sv, malloced_size(s));
+#else
         SvLEN_set(sv, newlen);
+#endif
     }
     return s;
 }
End of Patch.

Reply via email to