Change 32737 by [EMAIL PROTECTED] on 2007/12/26 18:12:32

        Take code that occurs in three places to take a scalar and ready it to
        hold a reference, and convert it to a macro define prepare_SV_for_RV().

Affected files ...

... //depot/perl/pp.c#608 edit
... //depot/perl/pp_hot.c#535 edit
... //depot/perl/sv.c#1452 edit
... //depot/perl/sv.h#328 edit

Differences ...

==== //depot/perl/pp.c#608 (text) ====
Index: perl/pp.c
--- perl/pp.c#607~32734~        2007-12-26 09:03:56.000000000 -0800
+++ perl/pp.c   2007-12-26 10:12:32.000000000 -0800
@@ -172,13 +172,7 @@
                        const char * const name = CopSTASHPV(PL_curcop);
                        gv = newGVgen(name);
                    }
-                   if (SvTYPE(sv) < SVt_PV && SvTYPE(sv) != SVt_IV)
-                       sv_upgrade(sv, SVt_IV);
-                   else if (SvPVX_const(sv)) {
-                       SvPV_free(sv);
-                       SvLEN_set(sv, 0);
-                        SvCUR_set(sv, 0);
-                   }
+                   prepare_SV_for_RV(sv);
                    SvRV_set(sv, (SV*)gv);
                    SvROK_on(sv);
                    SvSETMAGIC(sv);

==== //depot/perl/pp_hot.c#535 (text) ====
Index: perl/pp_hot.c
--- perl/pp_hot.c#534~32734~    2007-12-26 09:03:56.000000000 -0800
+++ perl/pp_hot.c       2007-12-26 10:12:32.000000000 -0800
@@ -2940,13 +2940,7 @@
     if (!SvOK(sv)) {
        if (SvREADONLY(sv))
            Perl_croak(aTHX_ PL_no_modify);
-       if (SvTYPE(sv) < SVt_PV && SvTYPE(sv) != SVt_IV)
-           sv_upgrade(sv, SVt_IV);
-       else if (SvTYPE(sv) >= SVt_PV) {
-           SvPV_free(sv);
-            SvLEN_set(sv, 0);
-           SvCUR_set(sv, 0);
-       }
+       prepare_SV_for_RV(sv);
        switch (to_what) {
        case OPpDEREF_SV:
            SvRV_set(sv, newSV(0));

==== //depot/perl/sv.c#1452 (text) ====
Index: perl/sv.c
--- perl/sv.c#1451~32734~       2007-12-26 09:03:56.000000000 -0800
+++ perl/sv.c   2007-12-26 10:12:32.000000000 -0800
@@ -7857,12 +7857,8 @@
        sv_upgrade(rv, SVt_IV);
     } else if (SvROK(rv)) {
        SvREFCNT_dec(SvRV(rv));
-    } else if (SvTYPE(rv) < SVt_PV && SvTYPE(rv) != SVt_IV)
-       sv_upgrade(rv, SVt_IV);
-    else if (SvTYPE(rv) >= SVt_PV) {
-       SvPV_free(rv);
-       SvCUR_set(rv, 0);
-       SvLEN_set(rv, 0);
+    } else {
+       prepare_SV_for_RV(rv);
     }
 
     SvOK_off(rv);

==== //depot/perl/sv.h#328 (text) ====
Index: perl/sv.h
--- perl/sv.h#327~32734~        2007-12-26 09:03:56.000000000 -0800
+++ perl/sv.h   2007-12-26 10:12:32.000000000 -0800
@@ -1441,6 +1441,20 @@
                     }                                                  \
                 } STMT_END
 
+#ifdef PERL_CORE
+/* Code that crops up in three places to take a scalar and ready it to hold
+   a reference */
+#  define prepare_SV_for_RV(sv)                                                
\
+    STMT_START {                                                       \
+                   if (SvTYPE(sv) < SVt_PV && SvTYPE(sv) != SVt_IV)    \
+                       sv_upgrade(sv, SVt_IV);                         \
+                   else if (SvPVX_const(sv)) {                         \
+                       SvPV_free(sv);                                  \
+                       SvLEN_set(sv, 0);                               \
+                        SvCUR_set(sv, 0);                              \
+                   }                                                   \
+                } STMT_END
+#endif
 
 #define PERL_FBM_TABLE_OFFSET 1        /* Number of bytes between EOS and 
table */
 
End of Patch.

Reply via email to