This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Performance optimisation in assert, suggested by Tim Bunce
authorRafael Garcia-Suarez <rgs@consttype.org>
Sun, 15 Nov 2009 00:34:03 +0000 (01:34 +0100)
committerRafael Garcia-Suarez <rgs@consttype.org>
Sun, 15 Nov 2009 00:34:48 +0000 (01:34 +0100)
Most compilers will store only a single copy of identical literal
strings. So changing that assert to check the pointer first would
significantly reduce the cost.

scope.h

diff --git a/scope.h b/scope.h
index 9fd3bce..2f50398 100644 (file)
--- a/scope.h
+++ b/scope.h
@@ -140,7 +140,9 @@ scope has the given name. Name must be a literal string.
 #define LEAVE_with_name(name)                                          \
     STMT_START {                                                       \
        DEBUG_SCOPE("LEAVE \"" name "\"")                               \
-       assert(strEQ(PL_scopestack_name[PL_scopestack_ix-1], name));    \
+       assert(((char*)PL_scopestack_name[PL_scopestack_ix-1]           \
+                   == (char*)name)                                     \
+               || strEQ(PL_scopestack_name[PL_scopestack_ix-1], name));        \
        pop_scope();                                                    \
     } STMT_END
 #else