Skip to content

Commit c74c422

Browse files
committed
unshare_hek_or_pvn: Use new utf8_to_bytes_new_pv()
1 parent cc59aa4 commit c74c422

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

hv.c

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3242,9 +3242,7 @@ S_unshare_hek_or_pvn(pTHX_ const HEK *hek, const char *str, I32 len, U32 hash)
32423242
{
32433243
HE *entry;
32443244
HE **oentry;
3245-
bool is_utf8 = FALSE;
32463245
int k_flags = 0;
3247-
const char * const save = str;
32483246
struct shared_he *he = NULL;
32493247

32503248
if (hek) {
@@ -3266,14 +3264,18 @@ S_unshare_hek_or_pvn(pTHX_ const HEK *hek, const char *str, I32 len, U32 hash)
32663264
hash = HEK_HASH(hek);
32673265
} else if (len < 0) {
32683266
STRLEN tmplen = -len;
3269-
is_utf8 = TRUE;
32703267
/* See the note in hv_fetch(). --jhi */
3271-
str = (char*)bytes_from_utf8((U8*)str, &tmplen, &is_utf8);
3272-
len = tmplen;
3273-
if (is_utf8)
3268+
U8 * free_str = NULL;
3269+
if (! utf8_to_bytes_new_pv(&str, &tmplen, &free_str)) {
32743270
k_flags = HVhek_UTF8;
3275-
if (str != save)
3276-
k_flags |= HVhek_WASUTF8 | HVhek_FREEKEY;
3271+
}
3272+
else {
3273+
k_flags |= HVhek_WASUTF8;
3274+
len = tmplen;
3275+
if (free_str) {
3276+
k_flags |= HVhek_FREEKEY;
3277+
}
3278+
}
32773279
}
32783280

32793281
/* what follows was the moral equivalent of:

0 commit comments

Comments
 (0)