there is no obvious reason not to set flags
authorRuslan Zakirov <ruz@bestpractical.com>
Fri, 5 Oct 2012 22:30:18 +0000 (02:30 +0400)
committerFather Chrysostomos <sprout@cpan.org>
Mon, 8 Oct 2012 15:49:54 +0000 (08:49 -0700)
I don't see any reason not to set flags properly in this
branch. It doesn't look like any useful optimization.

It's probably even a bug, but probably it can only be hit from
a XS code. To hit the bug keysv should be provided, be UTF8
and not SvIsCOW_shared_hash, but with flags containing
HVhek_KEYCANONICAL.

hv.c

diff --git a/hv.c b/hv.c
index 3b96101..c5e1206 100644 (file)
--- a/hv.c
+++ b/hv.c
@@ -388,7 +388,7 @@ Perl_hv_common(pTHX_ HV *hv, SV *keysv, const char *key, STRLEN klen,
        if (SvIsCOW_shared_hash(keysv)) {
            flags = HVhek_KEYCANONICAL | (is_utf8 ? HVhek_UTF8 : 0);
        } else {
-           flags = 0;
+           flags = is_utf8 ? HVhek_UTF8 : 0;
        }
     } else {
        is_utf8 = ((flags & HVhek_UTF8) ? TRUE : FALSE);
@@ -396,8 +396,7 @@ Perl_hv_common(pTHX_ HV *hv, SV *keysv, const char *key, STRLEN klen,
 
     if (action & HV_DELETE) {
        return (void *) hv_delete_common(hv, keysv, key, klen,
-                                        flags | (is_utf8 ? HVhek_UTF8 : 0),
-                                        action, hash);
+                                        flags, action, hash);
     }
 
     xhv = (XPVHV*)SvANY(hv);