summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteffen Mueller <smueller@cpan.org>2013-06-11 18:59:18 +0200
committerSteffen Mueller <smueller@cpan.org>2013-06-11 20:05:53 +0200
commit79e2a32a095274dde38cabdeca03b580bd9733d7 (patch)
tree9e0513736246e0dbe31ef7341efbf25454670b5b
parent586fc6a31347339bf2b16e391b44aa458f723283 (diff)
downloadperl-79e2a32a095274dde38cabdeca03b580bd9733d7.tar.gz
Branch prediction hint for SvREFCNT_dec
When decrementing the refcount on an SV, we have to branch on whether or not we've reached a refcount of 0. But a quick instrumentation shows that in virtually any program small or large, the number of decrements without freeing greatly outweighs the number of decrements that cause a free. Therefore, it's a net win to suggest to the compiler to emit a branch prediction hint to go into the just-decrement branch.
-rw-r--r--inline.h4
1 files changed, 2 insertions, 2 deletions
diff --git a/inline.h b/inline.h
index 953bb33cff..29a15acf60 100644
--- a/inline.h
+++ b/inline.h
@@ -67,7 +67,7 @@ S_SvREFCNT_dec(pTHX_ SV *sv)
{
if (LIKELY(sv != NULL)) {
U32 rc = SvREFCNT(sv);
- if (rc > 1)
+ if (LIKELY(rc > 1))
SvREFCNT(sv) = rc - 1;
else
Perl_sv_free2(aTHX_ sv, rc);
@@ -78,7 +78,7 @@ PERL_STATIC_INLINE void
S_SvREFCNT_dec_NN(pTHX_ SV *sv)
{
U32 rc = SvREFCNT(sv);
- if (rc > 1)
+ if (LIKELY(rc > 1))
SvREFCNT(sv) = rc - 1;
else
Perl_sv_free2(aTHX_ sv, rc);