Combine sv_utf8_upgrade with a following grow
Karl [Sun, 18 Jan 2009 22:34:58 +0000 (15:34 -0700)]
pp_ctl.c
sv.c
toke.c

index e9b4bfc..799683d 100644 (file)
--- a/pp_ctl.c
+++ b/pp_ctl.c
@@ -511,8 +511,7 @@ PP(pp_formline)
            if (!targ_is_utf8 && DO_UTF8(tmpForm)) {
                SvCUR_set(PL_formtarget, t - SvPVX_const(PL_formtarget));
                *t = '\0';
-               sv_utf8_upgrade(PL_formtarget);
-               SvGROW(PL_formtarget, SvCUR(PL_formtarget) + fudge + 1);
+               sv_utf8_upgrade_flags_grow(PL_formtarget, SV_GMAGIC, fudge + 1);
                t = SvEND(PL_formtarget);
                targ_is_utf8 = TRUE;
            }
@@ -695,8 +694,8 @@ PP(pp_formline)
                    if (!targ_is_utf8) {
                        SvCUR_set(PL_formtarget, t - SvPVX_const(PL_formtarget));
                        *t = '\0';
-                       sv_utf8_upgrade(PL_formtarget);
-                       SvGROW(PL_formtarget, SvCUR(PL_formtarget) + fudge + 1);
+                       sv_utf8_upgrade_flags_grow(PL_formtarget, SV_GMAGIC,
+                                                                   fudge + 1);
                        t = SvEND(PL_formtarget);
                        targ_is_utf8 = TRUE;
                    }
@@ -807,7 +806,7 @@ PP(pp_formline)
                                      t - SvPVX_const(PL_formtarget));
                            targ_is_utf8 = TRUE;
                            /* Don't need get magic.  */
-                           sv_utf8_upgrade_flags(PL_formtarget, 0);
+                           sv_utf8_upgrade_nomg(PL_formtarget);
                        } else {
                            SvCUR_set(PL_formtarget,
                                      t - SvPVX_const(PL_formtarget));
diff --git a/sv.c b/sv.c
index 0d6939f..d944e2f 100644 (file)
--- a/sv.c
+++ b/sv.c
@@ -4796,7 +4796,8 @@ Perl_sv_catsv_flags(pTHX_ SV *const dsv, register SV *const ssv, const I32 flags
                    spv = SvPV_const(csv, slen);
                }
                else
-                   sv_utf8_upgrade_nomg(dsv);
+                   /* Leave enough space for the cat that's about to happen */
+                   sv_utf8_upgrade_flags_grow(dsv, 0, slen);
            }
            sv_catpvn_nomg(dsv, spv, slen);
        }
diff --git a/toke.c b/toke.c
index 258c927..951c1ca 100644 (file)
--- a/toke.c
+++ b/toke.c
@@ -2306,9 +2306,10 @@ S_scan_const(pTHX_ char *start)
                        SvCUR_set(sv, d - SvPVX_const(sv));
                        SvPOK_on(sv);
                        *d = '\0';
-                       sv_utf8_upgrade(sv);
                        /* See Note on sizing above.  */
-                       SvGROW(sv, SvCUR(sv) + UNISKIP(uv) + (STRLEN)(send - s) + 1);
+                       sv_utf8_upgrade_flags_grow(sv,
+                                       SV_GMAGIC|SV_FORCE_UTF8_UPGRADE,
+                                       UNISKIP(uv) + (STRLEN)(send - s) + 1);
                        d = SvPVX(sv) + SvCUR(sv);
                        has_utf8 = TRUE;
                     }
@@ -2396,9 +2397,10 @@ S_scan_const(pTHX_ char *start)
                        SvCUR_set(sv, d - SvPVX_const(sv));
                        SvPOK_on(sv);
                        *d = '\0';
-                       sv_utf8_upgrade(sv);
                        /* See Note on sizing above.  */
-                       SvGROW(sv, SvCUR(sv) + len + (STRLEN)(send - s) + 1);
+                       sv_utf8_upgrade_flags_grow(sv,
+                                           SV_GMAGIC|SV_FORCE_UTF8_UPGRADE,
+                                           len + (STRLEN)(send - s) + 1);
                        d = SvPVX(sv) + SvCUR(sv);
                        has_utf8 = TRUE;
                    } else if (len > (STRLEN)(e - s + 4)) { /* I _guess_ 4 is \N{} --jhi */
@@ -2490,10 +2492,10 @@ S_scan_const(pTHX_ char *start)
                SvCUR_set(sv, d - SvPVX_const(sv));
                SvPOK_on(sv);
                *d = '\0';
-               sv_utf8_upgrade(sv);
-
                /* See Note on sizing above.  */
-               SvGROW(sv, SvCUR(sv) + need + (STRLEN)(send - s) + 1);
+               sv_utf8_upgrade_flags_grow(sv,
+                                       SV_GMAGIC|SV_FORCE_UTF8_UPGRADE,
+                                       need + (STRLEN)(send - s) + 1);
                d = SvPVX(sv) + SvCUR(sv);
                has_utf8 = TRUE;
            } else if (need > len) {