This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Perl_gv_fetchpvn_flags() can avoid copying when the package separator is ::
authorNicholas Clark <nick@ccl4.org>
Fri, 8 Oct 2010 14:39:24 +0000 (15:39 +0100)
committerNicholas Clark <nick@ccl4.org>
Fri, 8 Oct 2010 14:39:24 +0000 (15:39 +0100)
gv.c

diff --git a/gv.c b/gv.c
index db9617f..9e93937 100644 (file)
--- a/gv.c
+++ b/gv.c
@@ -1052,16 +1052,17 @@ Perl_gv_fetchpvn_flags(pTHX_ const char *nambeg, STRLEN full_len, I32 flags,
 
            len = name_cursor - name;
            if (len > 0) {
-               char smallbuf[128];
                char *tmpbuf;
 
-               if (len + 2 <= (I32)sizeof (smallbuf))
-                   tmpbuf = smallbuf;
-               else
+               if (name_cursor == ':') {
+                   tmpbuf = name;
+                   len += 2;
+               } else {
                    Newx(tmpbuf, len+2, char);
-               Copy(name, tmpbuf, len, char);
-               tmpbuf[len++] = ':';
-               tmpbuf[len++] = ':';
+                   Copy(name, tmpbuf, len, char);
+                   tmpbuf[len++] = ':';
+                   tmpbuf[len++] = ':';
+               }
                gvp = (GV**)hv_fetch(stash,tmpbuf,len,add);
                gv = gvp ? *gvp : NULL;
                if (gv && gv != (const GV *)&PL_sv_undef) {
@@ -1070,7 +1071,7 @@ Perl_gv_fetchpvn_flags(pTHX_ const char *nambeg, STRLEN full_len, I32 flags,
                    else
                        GvMULTI_on(gv);
                }
-               if (tmpbuf != smallbuf)
+               if (tmpbuf != name)
                    Safefree(tmpbuf);
                if (!gv || gv == (const GV *)&PL_sv_undef)
                    return NULL;