New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[PATCH] hv.c: add some SvREFCNT_dec_NN and S_hv_free_ent_ret NULL check removal #12668
Comments
From @bulk88See attached patch. |
From @bulk880001-hv.c-add-some-SvREFCNT_dec_NN-and-S_hv_free_ent_ret-.patchFrom 030ed137171a0d895b1b36f35c8a10c274a4535d Mon Sep 17 00:00:00 2001
From: Daniel Dragan <bulk88@hotmail.com>
Date: Sun, 23 Dec 2012 21:18:24 -0500
Subject: [PATCH] hv.c: add some SvREFCNT_dec_NN and S_hv_free_ent_ret NULL
check removal
Add some SvREFCNT_dec_NNs to hv.c. In hv_clear, stop 2 C level checks for
null. I didn't check the machine code to see if compiler optimized away
or not, but fix it on a C level anyways. Use Perl_croak_nocontext to save
a push instruction in threaded perls. In the 2 places where
S_hv_free_ent_ret is called (Perl_hv_free_ent and Perl_hfree_next_entry)
HE * entry is either checked for null, or dereferenced before the call to
S_hv_free_ent_ret. Change embed.fnc to reflect removal of the NULL check.
Purpose is less machine instructions/faster code.
---
embed.fnc | 2 +-
hv.c | 19 +++++++++----------
proto.h | 5 +++--
3 files changed, 13 insertions(+), 13 deletions(-)
diff --git a/embed.fnc b/embed.fnc
index 75688fb..1951bf3 100644
--- a/embed.fnc
+++ b/embed.fnc
@@ -1745,7 +1745,7 @@ po |SV* |hfree_next_entry |NN HV *hv|NN STRLEN *indexp
#if defined(PERL_IN_HV_C)
s |void |hsplit |NN HV *hv
s |void |hfreeentries |NN HV *hv
-s |SV* |hv_free_ent_ret|NN HV *hv|NULLOK HE *entryK
+s |SV* |hv_free_ent_ret|NN HV *hv|NN HE *entryK
sa |HE* |new_he
sanR |HEK* |save_hek_flags |NN const char *str|I32 len|U32 hash|int flags
sn |void |hv_magic_check |NN HV *hv|NN bool *needs_copy|NN bool *needs_store
diff --git a/hv.c b/hv.c
index 966a12f..5f7ae85 100644
--- a/hv.c
+++ b/hv.c
@@ -1377,7 +1377,7 @@ Perl_hv_copy_hints_hv(pTHX_ HV *const ohv)
else {
(void)hv_common(hv, heksv, HeKEY(entry), HeKLEN(entry),
HeKFLAGS(entry), HV_FETCH_ISSTORE|HV_FETCH_JUST_SV, sv, HeHASH(entry));
- SvREFCNT_dec(heksv);
+ SvREFCNT_dec_NN(heksv);
}
}
HvRITER_set(ohv, riter);
@@ -1399,8 +1399,6 @@ S_hv_free_ent_ret(pTHX_ HV *hv, HE *entry)
PERL_ARGS_ASSERT_HV_FREE_ENT_RET;
- if (!entry)
- return NULL;
val = HeVAL(entry);
if (HeKLEN(entry) == HEf_SVKEY) {
SvREFCNT_dec(HeKEY_sv(entry));
@@ -1481,14 +1479,15 @@ Perl_hv_clear(pTHX_ HV *hv)
for (; entry; entry = HeNEXT(entry)) {
/* not already placeholder */
if (HeVAL(entry) != &PL_sv_placeholder) {
- if (HeVAL(entry) && SvREADONLY(HeVAL(entry))
- && !SvIsCOW(HeVAL(entry))) {
- SV* const keysv = hv_iterkeysv(entry);
- Perl_croak(aTHX_
- "Attempt to delete readonly key '%"SVf"' from a restricted hash",
- (void*)keysv);
+ if (HeVAL(entry)) {
+ if (SvREADONLY(HeVAL(entry)) && !SvIsCOW(HeVAL(entry))) {
+ SV* const keysv = hv_iterkeysv(entry);
+ Perl_croak_nocontext(
+ "Attempt to delete readonly key '%"SVf"' from a restricted hash",
+ (void*)keysv);
+ }
+ SvREFCNT_dec_NN(HeVAL(entry));
}
- SvREFCNT_dec(HeVAL(entry));
HeVAL(entry) = &PL_sv_placeholder;
HvPLACEHOLDERS(hv)++;
}
diff --git a/proto.h b/proto.h
index ee2b14e..413434b 100644
--- a/proto.h
+++ b/proto.h
@@ -5685,9 +5685,10 @@ STATIC struct xpvhv_aux* S_hv_auxinit(HV *hv)
STATIC SV* S_hv_delete_common(pTHX_ HV *hv, SV *keysv, const char *key, STRLEN klen, int k_flags, I32 d_flags, U32 hash);
STATIC SV* S_hv_free_ent_ret(pTHX_ HV *hv, HE *entryK)
- __attribute__nonnull__(pTHX_1);
+ __attribute__nonnull__(pTHX_1)
+ __attribute__nonnull__(pTHX_2);
#define PERL_ARGS_ASSERT_HV_FREE_ENT_RET \
- assert(hv)
+ assert(hv); assert(entryK)
STATIC void S_hv_magic_check(HV *hv, bool *needs_copy, bool *needs_store)
__attribute__nonnull__(1)
--
1.7.9.msysgit.0
|
From @doughera88On Sun, 23 Dec 2012, bulk88 wrote:
[minor nit: This patch breaks a debugging build because embed.fnc I tried this patch and tested it on Linux/amd64 with gcc-4.7.2, It looks like this patch is doing good things -- avoiding redundant NULL In both cases, gcc inlines the S_hv_free_ent_ret function anyway, and the I also tested with Sun's cc compiler. It ended up giving the same So I'm not sure if it's worth applying or not. What do you think? -- |
The RT System itself - Status changed from 'new' to 'open' |
From @bulk88On Fri Jan 25 12:44:16 2013, doughera wrote:
I would say removing a null check is unmeasurable unless you are using
VC -O1 doesn't inline SvREFCNT_dec_NN or S_hv_free_ent_ret.
I would apply it. There were a couple of other places in hv.c where I I use -O1. Are you using a threaded or unthreaded perl? is your sun x86 -- |
From @tseeOn 01/25/2013 09:43 PM, Andy Dougherty wrote:
All of this just my opinion: Unless there's a particular reason --Steffen |
From @iabynOn Sat, Jan 26, 2013 at 11:16:37AM +0100, Steffen Mueller wrote:
I agree. Regardless of any insignificant performance gains, the new code but I rewrote the commit message to be clearer. -- |
From @doughera88On Fri, 25 Jan 2013, bulk88 via RT wrote:
I'm afraid I have no idea what 'rdtsc' is, nor what you mean by 'perf
There are too many combinations. Depending on what else is going on, I -- |
From @tonycozOn Tue Jan 29 03:19:44 2013, davem wrote:
Unfortunately you messed up the author email address. The attached patch has headers: From 030ed137171a0d895b1b36f35c8a10c274a4535d Mon Sep 17 00:00:00 2001 but I guess you <git am>ed the whole mailbox entry instead of the Tony |
From @bulk88On Tue Jan 29 19:09:07 2013, tonyc wrote:
I think its time for a git hook to stop any commits with perlbug as the -- |
@iabyn - Status changed from 'open' to 'resolved' |
Migrated from rt.perl.org#116188 (status was 'resolved')
Searchable as RT116188$
The text was updated successfully, but these errors were encountered: