Change 27533 by [EMAIL PROTECTED] on 2006/03/17 13:38:34

        sv_find() returning false, followed by sv_magic() to add the magic,
        followed immediately by sv_find() to find it, is somewhat wasteful.
        So use sv_magicext(). (All cases are also correct w.r.t. SvREADONLY())

Affected files ...

... //depot/perl/mg.c#421 edit
... //depot/perl/pp_ctl.c#533 edit
... //depot/perl/pp_hot.c#459 edit
... //depot/perl/regexec.c#377 edit
... //depot/perl/sv.c#1187 edit

Differences ...

==== //depot/perl/mg.c#421 (text) ====
Index: perl/mg.c
--- perl/mg.c#420~27525~        2006-03-16 15:11:11.000000000 -0800
+++ perl/mg.c   2006-03-17 05:38:34.000000000 -0800
@@ -1803,8 +1803,12 @@
     if (!mg) {
        if (!SvOK(sv))
            return 0;
-       sv_magic(lsv, NULL, PERL_MAGIC_regex_global, NULL, 0);
-       mg = mg_find(lsv, PERL_MAGIC_regex_global);
+#ifdef PERL_OLD_COPY_ON_WRITE
+    if (SvIsCOW(lsv))
+        sv_force_normal_flags(lsv, 0);
+#endif
+       mg = sv_magicext(lsv, NULL, PERL_MAGIC_regex_global, &PL_vtbl_mglob,
+                        NULL, 0);
     }
     else if (!SvOK(sv)) {
        mg->mg_len = -1;

==== //depot/perl/pp_ctl.c#533 (text) ====
Index: perl/pp_ctl.c
--- perl/pp_ctl.c#532~27515~    2006-03-16 04:01:10.000000000 -0800
+++ perl/pp_ctl.c       2006-03-17 05:38:34.000000000 -0800
@@ -284,8 +284,12 @@
        if (SvTYPE(sv) < SVt_PVMG)
            SvUPGRADE(sv, SVt_PVMG);
        if (!(mg = mg_find(sv, PERL_MAGIC_regex_global))) {
-           sv_magic(sv, NULL, PERL_MAGIC_regex_global, NULL, 0);
-           mg = mg_find(sv, PERL_MAGIC_regex_global);
+#ifdef PERL_OLD_COPY_ON_WRITE
+           if (SvIsCOW(lsv))
+               sv_force_normal_flags(sv, 0);
+#endif
+           mg = sv_magicext(sv, NULL, PERL_MAGIC_regex_global, &PL_vtbl_mglob,
+                            NULL, 0);
        }
        i = m - orig;
        if (DO_UTF8(sv))

==== //depot/perl/pp_hot.c#459 (text) ====
Index: perl/pp_hot.c
--- perl/pp_hot.c#458~27414~    2006-03-08 02:25:26.000000000 -0800
+++ perl/pp_hot.c       2006-03-17 05:38:34.000000000 -0800
@@ -1405,8 +1405,12 @@
                if (SvTYPE(TARG) >= SVt_PVMG && SvMAGIC(TARG))
                    mg = mg_find(TARG, PERL_MAGIC_regex_global);
                if (!mg) {
-                   sv_magic(TARG, NULL, PERL_MAGIC_regex_global, NULL, 0);
-                   mg = mg_find(TARG, PERL_MAGIC_regex_global);
+#ifdef PERL_OLD_COPY_ON_WRITE
+                   if (SvIsCOW(TARG))
+                       sv_force_normal_flags(TARG, 0);
+#endif
+                   mg = sv_magicext(TARG, NULL, PERL_MAGIC_regex_global,
+                                    &PL_vtbl_mglob, NULL, 0);
                }
                if (rx->startp[0] != -1) {
                    mg->mg_len = rx->endp[0];
@@ -1435,8 +1439,12 @@
            else
                mg = NULL;
            if (!mg) {
-               sv_magic(TARG, NULL, PERL_MAGIC_regex_global, NULL, 0);
-               mg = mg_find(TARG, PERL_MAGIC_regex_global);
+#ifdef PERL_OLD_COPY_ON_WRITE
+               if (SvIsCOW(TARG))
+                   sv_force_normal_flags(TARG, 0);
+#endif
+               mg = sv_magicext(TARG, NULL, PERL_MAGIC_regex_global,
+                                &PL_vtbl_mglob, NULL, 0);
            }
            if (rx->startp[0] != -1) {
                mg->mg_len = rx->endp[0];

==== //depot/perl/regexec.c#377 (text) ====
Index: perl/regexec.c
--- perl/regexec.c#376~27526~   2006-03-16 18:57:45.000000000 -0800
+++ perl/regexec.c      2006-03-17 05:38:34.000000000 -0800
@@ -2130,9 +2130,12 @@
            if (!(SvTYPE(PL_reg_sv) >= SVt_PVMG && SvMAGIC(PL_reg_sv)
                  && (mg = mg_find(PL_reg_sv, PERL_MAGIC_regex_global)))) {
                /* prepare for quick setting of pos */
-               sv_magic(PL_reg_sv, (SV*)0,
-                       PERL_MAGIC_regex_global, NULL, 0);
-               mg = mg_find(PL_reg_sv, PERL_MAGIC_regex_global);
+#ifdef PERL_OLD_COPY_ON_WRITE
+               if (SvIsCOW(sv))
+                   sv_force_normal_flags(sv, 0);
+#endif
+               mg = sv_magicext(PL_reg_sv, (SV*)0, PERL_MAGIC_regex_global,
+                                &PL_vtbl_mglob, NULL, 0);
                mg->mg_len = -1;
            }
            PL_reg_magic    = mg;

==== //depot/perl/sv.c#1187 (text) ====
Index: perl/sv.c
--- perl/sv.c#1186~27506~       2006-03-15 07:08:49.000000000 -0800
+++ perl/sv.c   2006-03-17 05:38:34.000000000 -0800
@@ -5943,8 +5943,12 @@
                return xf + sizeof(PL_collation_ix);
            }
            if (! mg) {
-               sv_magic(sv, 0, PERL_MAGIC_collxfrm, 0, 0);
-               mg = mg_find(sv, PERL_MAGIC_collxfrm);
+#ifdef PERL_OLD_COPY_ON_WRITE
+               if (SvIsCOW(sv))
+                   sv_force_normal_flags(sv, 0);
+#endif
+               mg = sv_magicext(sv, 0, PERL_MAGIC_collxfrm, &PL_vtbl_collxfrm,
+                                0, 0);
                assert(mg);
            }
            mg->mg_ptr = xf;
End of Patch.

Reply via email to