delete() should return the value as is, not a copy thereof
authorGurusamy Sarathy <gsar@cpan.org>
Fri, 17 Dec 1999 18:09:08 +0000 (18:09 +0000)
committerGurusamy Sarathy <gsar@cpan.org>
Fri, 17 Dec 1999 18:09:08 +0000 (18:09 +0000)
p4raw-id: //depot/perl@4694

hv.c
pod/perldelta.pod

diff --git a/hv.c b/hv.c
index c591cbf..8431cf7 100644 (file)
--- 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
index 2ea14a2..f681859 100644 (file)
@@ -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