summaryrefslogtreecommitdiff
path: root/hv.c
diff options
context:
space:
mode:
authorNicholas Clark <nick@ccl4.org>2008-12-28 13:06:42 +0000
committerNicholas Clark <nick@ccl4.org>2008-12-28 13:06:42 +0000
commit44b87b5061968d098b3906ca4b5e6f94469c8694 (patch)
tree26dc3bef2d40170577a915a2d8e0b4aa4559dcf8 /hv.c
parent90acdc2acfdb8c512ef84ee08df225ccf527f635 (diff)
downloadperl-44b87b5061968d098b3906ca4b5e6f94469c8694.tar.gz
Add a key flag HVhek_KEYCANONICAL for Perl_hv_common(), which signals that the
key is in canonical form - any key passed encoded in UTF-8 cannot be represented as bytes, hence the downgrade check can be skipped. Use this internally for shared hash key scalars, as they are always canonical.
Diffstat (limited to 'hv.c')
-rw-r--r--hv.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/hv.c b/hv.c
index b764c5593e..79f59730a9 100644
--- a/hv.c
+++ b/hv.c
@@ -388,8 +388,12 @@ Perl_hv_common(pTHX_ HV *hv, SV *keysv, const char *key, STRLEN klen,
if (flags & HVhek_FREEKEY)
Safefree(key);
key = SvPV_const(keysv, klen);
- flags = 0;
is_utf8 = (SvUTF8(keysv) != 0);
+ if (SvIsCOW_shared_hash(keysv)) {
+ flags = HVhek_KEYCANONICAL | (is_utf8 ? HVhek_UTF8 : 0);
+ } else {
+ flags = 0;
+ }
} else {
is_utf8 = ((flags & HVhek_UTF8) ? TRUE : FALSE);
}
@@ -595,7 +599,7 @@ Perl_hv_common(pTHX_ HV *hv, SV *keysv, const char *key, STRLEN klen,
}
}
- if (is_utf8) {
+ if (is_utf8 & !(flags & HVhek_KEYCANONICAL)) {
char * const keysave = (char *)key;
key = (char*)bytes_from_utf8((U8*)key, &klen, &is_utf8);
if (is_utf8)