diff options
author | Jarkko Hietaniemi <jhi@iki.fi> | 2002-03-22 04:07:13 +0000 |
---|---|---|
committer | Jarkko Hietaniemi <jhi@iki.fi> | 2002-03-22 04:07:13 +0000 |
commit | 574c8022b1fdc7312bf9a5af037c8f777b60b6db (patch) | |
tree | 06b4317b44c20a0a8683822193a3359385f3c9bf /hv.c | |
parent | 3fbcfac442ddabdaab668242ba16ca26c5edd56c (diff) | |
download | perl-574c8022b1fdc7312bf9a5af037c8f777b60b6db.tar.gz |
If Unicode keys are entered to a hash, a bit is turned on.
If the bit is on, when the keys are fetched from the hash
(%h, each %h, keys %h), the Unicodified versions of the keys
are returned if needed. This solution errs on the size of
over-Unicodifying, the old solution erred on the side of
under-Unicodifying. As long as the hash keys can be a mix
of byte and Unicode strings, a perfect fit is hard to come by.
p4raw-id: //depot/perl@15407
Diffstat (limited to 'hv.c')
-rw-r--r-- | hv.c | 16 |
1 files changed, 15 insertions, 1 deletions
@@ -488,11 +488,13 @@ Perl_hv_store(pTHX_ HV *hv, const char *key, I32 klen, SV *val, register U32 has #endif } } + if (is_utf8) { STRLEN tmplen = klen; /* See the note in hv_fetch(). --jhi */ key = (char*)bytes_from_utf8((U8*)key, &tmplen, &is_utf8); klen = tmplen; + HvUTF8KEYS_on((SV*)hv); } if (!hash) @@ -615,8 +617,10 @@ Perl_hv_store_ent(pTHX_ HV *hv, SV *keysv, SV *val, register U32 hash) keysave = key = SvPV(keysv, klen); is_utf8 = (SvUTF8(keysv) != 0); - if (is_utf8) + if (is_utf8) { key = (char*)bytes_from_utf8((U8*)key, &klen, &is_utf8); + HvUTF8KEYS_on((SV*)hv); + } if (!hash) PERL_HASH(hash, key, klen); @@ -773,6 +777,8 @@ Perl_hv_delete(pTHX_ HV *hv, const char *key, I32 klen, I32 flags) else hv_free_ent(hv, entry); xhv->xhv_keys--; /* HvKEYS(hv)-- */ + if (xhv->xhv_keys == 0) + HvUTF8KEYS_off(hv); xhv->xhv_placeholders--; return Nullsv; } @@ -810,6 +816,8 @@ Perl_hv_delete(pTHX_ HV *hv, const char *key, I32 klen, I32 flags) else hv_free_ent(hv, entry); xhv->xhv_keys--; /* HvKEYS(hv)-- */ + if (xhv->xhv_keys == 0) + HvUTF8KEYS_off(hv); } return sv; } @@ -920,6 +928,8 @@ Perl_hv_delete_ent(pTHX_ HV *hv, SV *keysv, I32 flags, U32 hash) else hv_free_ent(hv, entry); xhv->xhv_keys--; /* HvKEYS(hv)-- */ + if (xhv->xhv_keys == 0) + HvUTF8KEYS_off(hv); xhv->xhv_placeholders--; return Nullsv; } @@ -956,6 +966,8 @@ Perl_hv_delete_ent(pTHX_ HV *hv, SV *keysv, I32 flags, U32 hash) else hv_free_ent(hv, entry); xhv->xhv_keys--; /* HvKEYS(hv)-- */ + if (xhv->xhv_keys == 0) + HvUTF8KEYS_off(hv); } return sv; } @@ -1478,6 +1490,8 @@ Perl_hv_clear(pTHX_ HV *hv) if (SvRMAGICAL(hv)) mg_clear((SV*)hv); + + HvUTF8KEYS_off(hv); } STATIC void |