This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Have newATTRSUB remember the name’s length
authorFather Chrysostomos <sprout@cpan.org>
Sun, 20 Nov 2011 07:23:27 +0000 (23:23 -0800)
committerFather Chrysostomos <sprout@cpan.org>
Sun, 20 Nov 2011 22:14:00 +0000 (14:14 -0800)
Now that newCONSTSUB_flags has a length parameter, new ATTRSUB can
record the length and pass that to newCONSTSUB_flags, instead of using
strlen to get it.

op.c

diff --git a/op.c b/op.c
index 5d059d3..d4d4a05 100644 (file)
--- a/op.c
+++ b/op.c
@@ -6473,7 +6473,8 @@ Perl_newATTRSUB(pTHX_ I32 floor, OP *o, OP *proto, OP *attrs, OP *block)
        = (block || attrs || (CvFLAGS(PL_compcv) & CVf_BUILTIN_ATTRS)
           || PL_madskills)
        ? GV_ADDMULTI : GV_ADDMULTI | GV_NOINIT;
-    const char * const name = o ? SvPV_nolen_const(cSVOPo->op_sv) : NULL;
+    STRLEN namlen = 0;
+    const char * const name = o ? SvPV_const(cSVOPo->op_sv, namlen) : NULL;
     bool has_name;
     bool name_is_utf8 = o ? (SvUTF8(cSVOPo->op_sv) ? 1 : 0) : 0;
 
@@ -6620,7 +6621,7 @@ Perl_newATTRSUB(pTHX_ I32 floor, OP *o, OP *proto, OP *attrs, OP *block)
        else {
            GvCV_set(gv, NULL);
            cv = newCONSTSUB_flags(
-               NULL, name, name ? strlen(name) : 0, name_is_utf8 ? SVf_UTF8 : 0,
+               NULL, name, namlen, name_is_utf8 ? SVf_UTF8 : 0,
                const_sv
            );
        }