From: Gurusamy Sarathy Date: Fri, 17 Dec 1999 18:09:08 +0000 (+0000) Subject: delete() should return the value as is, not a copy thereof X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=94f7643d7f26ed53393f1ab3452245da43de285e;p=p5sagit%2Fp5-mst-13.2.git delete() should return the value as is, not a copy thereof p4raw-id: //depot/perl@4694 --- diff --git a/hv.c b/hv.c index c591cbf..8431cf7 100644 --- a/hv.c +++ b/hv.c @@ -502,8 +502,10 @@ Perl_hv_delete(pTHX_ HV *hv, const char *key, U32 klen, I32 flags) xhv->xhv_fill--; if (flags & G_DISCARD) sv = Nullsv; - else - sv = sv_mortalcopy(HeVAL(entry)); + else { + sv = HeVAL(entry); + HeVAL(entry) = &PL_sv_undef; + } if (entry == xhv->xhv_eiter) HvLAZYDEL_on(hv); else @@ -576,8 +578,10 @@ Perl_hv_delete_ent(pTHX_ HV *hv, SV *keysv, I32 flags, U32 hash) xhv->xhv_fill--; if (flags & G_DISCARD) sv = Nullsv; - else - sv = sv_mortalcopy(HeVAL(entry)); + else { + sv = HeVAL(entry); + HeVAL(entry) = &PL_sv_undef; + } if (entry == xhv->xhv_eiter) HvLAZYDEL_on(hv); else diff --git a/pod/perldelta.pod b/pod/perldelta.pod index 2ea14a2..f681859 100644 --- a/pod/perldelta.pod +++ b/pod/perldelta.pod @@ -95,9 +95,9 @@ but still allowed it. In Perl 5.6 and later, C<"$$1"> always means C<"${$1}">. -=item values(%h) and C<\(%h)> operate on aliases to values, not copies +=item delete(), values() and C<\(%h)> operate on aliases to values, not copies -each(), values() and hashes in a list context return the actual +delete(), each(), values() and hashes in a list context return the actual values in the hash, instead of copies (as they used to in earlier versions). Typical idioms for using these constructs copy the returned values, but this can make a significant difference when