pp.c pp_argelem() dont make SV* tmp bufs in a loop to strip GMG #23445
+8
−2
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Alloc the mortal string scratch pad SV* only once and reuse it for every iteration to strip GMG from each SV* key. hv_store_ent() never RC++s ownership of the callers SV* key arg.
Although it makes no difference either way for pp_argelem(), because it is an internal detail of sv.c Use any type of PV COW if available. If a shared HEK COW is delivered into the tmp SV*, even better b/c of hv_store_ent()'s optimization for that.
Worst case keynomg has a Newx() buffer that only reallocs 1x or 2x before flatlining for the rest of the loop which is still very good.
I think, but I can't confirm, that this copy code was added b/c of a GMG getter firing order issue so val doesn't GMG b4 key, or because maybe its not possible to prevent hv_common() keysv GMG from firing so SvGETMAGIC() can't be used to reverse GMG firing order, or maybe if a keysv GMG getter throws an exception inside hv_common(), tmpsv is leaked.
The make multiple mortal SV PVs in a loop code is from day 1 of this opcode in commit 4fa0684 - davem - 7/9/2016 5:41:08 AM
"add OP_ARGELEM, OP_ARGDEFELEM, OP_ARGCHECK ops"