summaryrefslogtreecommitdiff
path: root/hv.c
diff options
context:
space:
mode:
authorNicholas Clark <nick@ccl4.org>2021-07-26 09:28:15 +0000
committerNicholas Clark <nick@ccl4.org>2021-09-18 18:40:19 +0000
commitd15612fefdeea3e8baf64a5409a5385b54db76b1 (patch)
treefe395326db958053d516f8a3a085315c7c9d8028 /hv.c
parent73ace1cb5078023d3dca765f0f10329b8606fc05 (diff)
downloadperl-d15612fefdeea3e8baf64a5409a5385b54db76b1.tar.gz
Merge the two `d_flags & G_DISCARD` tests in hv_delete_common()
Read from HeVAL() once, and move the call to sv_2mortal() later.
Diffstat (limited to 'hv.c')
-rw-r--r--hv.c23
1 files changed, 13 insertions, 10 deletions
diff --git a/hv.c b/hv.c
index 7f4a2e83db..cd962f6e34 100644
--- a/hv.c
+++ b/hv.c
@@ -1245,13 +1245,15 @@ S_hv_delete_common(pTHX_ HV *hv, SV *keysv, const char *key, STRLEN klen,
Perl_croak(aTHX_ S_strtab_error, "delete");
}
+ sv = HeVAL(entry);
+
/* if placeholder is here, it's already been deleted.... */
- if (HeVAL(entry) == &PL_sv_placeholder) {
+ if (sv == &PL_sv_placeholder) {
if (k_flags & HVhek_FREEKEY)
Safefree(key);
return NULL;
}
- if (SvREADONLY(hv) && HeVAL(entry) && SvREADONLY(HeVAL(entry))) {
+ if (SvREADONLY(hv) && sv && SvREADONLY(sv)) {
hv_notallowed(k_flags, key, klen,
"Attempt to delete readonly key '%" SVf "' from"
" a restricted hash");
@@ -1260,8 +1262,8 @@ S_hv_delete_common(pTHX_ HV *hv, SV *keysv, const char *key, STRLEN klen,
/* If this is a stash and the key ends with ::, then someone is
* deleting a package.
*/
- if (HeVAL(entry) && HvENAME_get(hv)) {
- gv = (GV *)HeVAL(entry);
+ if (sv && HvENAME_get(hv)) {
+ gv = (GV *)sv;
if ((
(klen > 1 && key[klen-2] == ':' && key[klen-1] == ':')
||
@@ -1353,8 +1355,6 @@ S_hv_delete_common(pTHX_ HV *hv, SV *keysv, const char *key, STRLEN klen,
if (k_flags & HVhek_FREEKEY)
Safefree(key);
- sv = d_flags & G_DISCARD ? HeVAL(entry) : sv_2mortal(HeVAL(entry));
-
/*
* If a restricted hash, rather than really deleting the entry, put
* a placeholder there. This marks the key as being "approved", so
@@ -1388,11 +1388,14 @@ S_hv_delete_common(pTHX_ HV *hv, SV *keysv, const char *key, STRLEN klen,
if (isGV(sv) && isGV_with_GP(sv) && GvCVu(sv)
&& HvENAME_get(hv))
mro_method_changed_in(hv);
- }
- if (d_flags & G_DISCARD) {
- SvREFCNT_dec(sv);
- sv = NULL;
+ if (d_flags & G_DISCARD) {
+ SvREFCNT_dec(sv);
+ sv = NULL;
+ }
+ else {
+ sv_2mortal(sv);
+ }
}
if (mro_changes == 1) mro_isa_changed_in(hv);