[svn:ponie] r360 - trunk/perl

[email protected] 17 Oct 2005 20:43:48 -0000
Newsgroups perl.ponie.changes
Message-ID <[email protected]>
Author: nicholas
Date: Mon Oct 17 13:43:47 2005
New Revision: 360

Modified:
   trunk/perl/sv.c
   trunk/perl/sv.h
Log:
SvREFCNT is a hash lookup now, rather than a structure access, so it is slow.
caching it seems to save about 1.5% CPU time on the tests. Maybe noise, maybe
not.


Modified: trunk/perl/sv.c
==============================================================================
--- trunk/perl/sv.c	(original)
+++ trunk/perl/sv.c	Mon Oct 17 13:43:47 2005
@@ -4984,9 +4984,13 @@ Normally called via a wrapper macro C<Sv
 void
 Perl_sv_free(pTHX_ SV *sv)
 {
+    /* XXX Beware. This assumes that SvREFCNT reports the truth.
+       But for now the speed gain is worth it.  */
+    U32 refcnt;
     if (!sv)
 	return;
-    if (SvREFCNT(sv) == 0) {
+    refcnt = SvREFCNT(sv);
+    if (refcnt == 0) {
 	if (SvBREAK(sv))
 	    /* this SV's refcnt has been artificially decremented to
 	     * trigger cleanup */
@@ -5012,7 +5016,7 @@ Perl_sv_free(pTHX_ SV *sv)
     /* --SvREFCNT(sv) becomes:  */
     Parrot_PMC_set_intval_intkey(PL_Parrot, MUMBLE(sv),
 				 Ponie_I_SV_REFCNT_INC, -1);
-    if (SvREFCNT(sv) > 0)
+    if ((refcnt - 1) > 0)
 	return;
     Perl_sv_free2(aTHX_ sv);
 }

Modified: trunk/perl/sv.h
==============================================================================
--- trunk/perl/sv.h	(original)
+++ trunk/perl/sv.h	Mon Oct 17 13:43:47 2005
@@ -130,14 +130,17 @@ perform the upgrade if necessary.  See C
 #endif
 
 #if defined(__GNUC__) && !defined(__STRICT_ANSI__) && !defined(PERL_GCC_PEDANTIC)
+/* XXX Beware. This assumes that SvREFCNT reports the truth.
+   But for now the speed gain is worth it.  */
 #  define SvREFCNT_dec(sv)		\
     ({					\
 	SV *_sv = (SV*)(sv);		\
 	if (_sv) {			\
-	    if (SvREFCNT(_sv)) {	\
+	    const U32 refcnt = SvREFCNT(_sv); \
+	    if (refcnt) {	\
 		Parrot_PMC_set_intval_intkey(PL_Parrot, MUMBLE(_sv), \
 					     Ponie_I_SV_REFCNT_INC, -1); \
-		if ((SvREFCNT(_sv)) == 0) \
+		if (refcnt - 1 == 0) \
 		    Perl_sv_free2(aTHX_ _sv);	\
 	    } else {			\
 		sv_free(_sv);		\