Storing the length of all the overloading names saves a strlen() in a
authorNicholas Clark <nick@ccl4.org>
Wed, 17 Oct 2007 15:10:58 +0000 (15:10 +0000)
committerNicholas Clark <nick@ccl4.org>
Wed, 17 Oct 2007 15:10:58 +0000 (15:10 +0000)
loop in Perl_Gv_AMupdate().
Brought to you by the Campaign for the Elimination of strlen().

p4raw-id: //depot/perl@32124

gv.c
overload.c
overload.pl

diff --git a/gv.c b/gv.c
index 8c0b4e1..1b4816d 100644 (file)
--- a/gv.c
+++ b/gv.c
@@ -1586,7 +1586,7 @@ Perl_Gv_AMupdate(pTHX_ HV *stash)
        const char * const cooky = PL_AMG_names[i];
        /* Human-readable form, for debugging: */
        const char * const cp = (i >= DESTROY_amg ? cooky : AMG_id2name(i));
-       const STRLEN l = strlen(cooky);
+       const STRLEN l = PL_AMG_namelens[i];
 
        DEBUG_o( Perl_deb(aTHX_ "Checking overloading of \"%s\" in package \"%.256s\"\n",
                     cp, HvNAME_get(stash)) );
index 0a220cc..bb7f1cb 100644 (file)
 
 #define AMG_id2name(id) (PL_AMG_names[id]+1)
 
+const U8 PL_AMG_namelens[NofAMmeth] = {
+    2,
+    4,
+    4,
+    4,
+    4,
+    4,
+    3,
+    3,
+    5,
+    3,
+    3,
+    2,
+    2,
+    4,
+    4,
+    3,
+    4,
+    2,
+    3,
+    2,
+    3,
+    3,
+    3,
+    3,
+    3,
+    3,
+    3,
+    3,
+    3,
+    9,
+    2,
+    3,
+    2,
+    3,
+    2,
+    3,
+    2,
+    3,
+    2,
+    3,
+    3,
+    4,
+    3,
+    4,
+    3,
+    4,
+    2,
+    3,
+    2,
+    3,
+    2,
+    3,
+    4,
+    4,
+    2,
+    6,
+    4,
+    4,
+    4,
+    4,
+    5,
+    2,
+    3,
+    2,
+    3,
+    3,
+    7
+};
+
 char * const PL_AMG_names[NofAMmeth] = {
   /* Names kept in the symbol table.  fallback => "()", the rest has
      "(" prepended.  The only other place in perl which knows about
index 9def29f..6b1050e 100644 (file)
@@ -71,15 +71,26 @@ print C <<'EOF';
 
 #define AMG_id2name(id) (PL_AMG_names[id]+1)
 
+const U8 PL_AMG_namelens[NofAMmeth] = {
+EOF
+
+my $last = pop @names;
+
+print C "    $_,\n" foreach map { length $_ } @names;
+
+my $lastlen = length $last;
+print C <<"EOT";
+    $lastlen
+};
+
 char * const PL_AMG_names[NofAMmeth] = {
   /* Names kept in the symbol table.  fallback => "()", the rest has
      "(" prepended.  The only other place in perl which knows about
      this convention is AMG_id2name (used for debugging output and
      'nomethod' only), the only other place which has it hardwired is
      overload.pm.  */
-EOF
+EOT
 
-my $last = pop @names;
 print C "    \"$_\",\n" foreach map { s/(["\\"])/\\$1/g; $_ } @names;
 
 print C <<"EOT";
@@ -88,6 +99,7 @@ print C <<"EOT";
 EOT
 
 close H or die $!;
+close C or die $!;
 
 __DATA__
 # Fallback should be the first