This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Introduce newSVpvs_share() macro.
authorGisle Aas <gisle@activestate.com>
Wed, 4 Jan 2006 14:04:16 +0000 (14:04 +0000)
committerGisle Aas <gisle@activestate.com>
Wed, 4 Jan 2006 14:04:16 +0000 (14:04 +0000)
Gets rid of some hardcoded string lengths.

p4raw-id: //depot/perl@26646

op.c
perl.c
sv.h

diff --git a/op.c b/op.c
index e14b4e6..7b72182 100644 (file)
--- a/op.c
+++ b/op.c
@@ -1624,7 +1624,7 @@ S_apply_attrs_my(pTHX_ HV *stash, OP *target, OP *attrs, OP **imopsp)
                                    dup_attrlist(attrs)));
 
     /* Fake up a method call to import */
-    meth = newSVpvn_share("import", 6, 0);
+    meth = newSVpvs_share("import");
     imop = convert(OP_ENTERSUB, OPf_STACKED|OPf_SPECIAL|OPf_WANT_VOID,
                   append_elem(OP_LIST,
                               prepend_elem(OP_LIST, pack, list(arg)),
@@ -3071,7 +3071,7 @@ Perl_utilize(pTHX_ int aver, I32 floor, OP *version, OP *idop, OP *arg)
            pack = newSVOP(OP_CONST, 0, newSVsv(((SVOP*)idop)->op_sv));
 
            /* Fake up a method call to VERSION */
-           meth = newSVpvn_share("VERSION", 7, 0);
+           meth = newSVpvs_share("VERSION");
            veop = convert(OP_ENTERSUB, OPf_STACKED|OPf_SPECIAL,
                            append_elem(OP_LIST,
                                        prepend_elem(OP_LIST, pack, list(version)),
@@ -3095,7 +3095,7 @@ Perl_utilize(pTHX_ int aver, I32 floor, OP *version, OP *idop, OP *arg)
 
        /* Fake up a method call to import/unimport */
        meth = aver
-           ? newSVpvn_share("import",6, 0) : newSVpvn_share("unimport", 8, 0);
+           ? newSVpvs_share("import") : newSVpvs_share("unimport");
        imop = convert(OP_ENTERSUB, OPf_STACKED|OPf_SPECIAL,
                       append_elem(OP_LIST,
                                   prepend_elem(OP_LIST, pack, list(arg)),
@@ -3104,7 +3104,7 @@ Perl_utilize(pTHX_ int aver, I32 floor, OP *version, OP *idop, OP *arg)
 
     /* Fake up the BEGIN {}, which does its thing immediately. */
     newATTRSUB(floor,
-       newSVOP(OP_CONST, 0, newSVpvn_share("BEGIN", 5, 0)),
+       newSVOP(OP_CONST, 0, newSVpvs_share("BEGIN")),
        Nullop,
        Nullop,
        append_elem(OP_LINESEQ,
diff --git a/perl.c b/perl.c
index 1aff49d..728f91c 100644 (file)
--- a/perl.c
+++ b/perl.c
@@ -3453,7 +3453,7 @@ S_init_main_stash(pTHX)
     /* We know that the string "main" will be in the global shared string
        table, so it's a small saving to use it rather than allocate another
        8 bytes.  */
-    PL_curstname = newSVpvn_share("main", 4, 0);
+    PL_curstname = newSVpvs_share("main");
     gv = gv_fetchpv("main::",TRUE, SVt_PVHV);
     /* If we hadn't caused another reference to "main" to be in the shared
        string table above, then it would be worth reordering these two,
diff --git a/sv.h b/sv.h
index f2bbe10..479b442 100644 (file)
--- a/sv.h
+++ b/sv.h
@@ -1426,6 +1426,7 @@ Like C<sv_catsv> but doesn't process magic.
 #define sv_2uv(sv) sv_2uv_flags(sv, SV_GMAGIC)
 
 #define newSVpvs(str) newSVpvn(STR_WITH_LEN(str))
+#define newSVpvs_share(str) newSVpvn_share(STR_WITH_LEN(str), 0)
 #define sv_catpvs(sv, str) sv_catpvn_flags(sv, STR_WITH_LEN(str), SV_GMAGIC)
 
 /* Should be named SvCatPVN_utf8_upgrade? */