diff --git a/include/hxString.h b/include/hxString.h index a140167eb..5fd402561 100644 --- a/include/hxString.h +++ b/include/hxString.h @@ -228,8 +228,8 @@ class HXCPP_EXTERN_CLASS_ATTRIBUTES String #ifdef HXCPP_PARANOID unsigned int result = calcHash(); - unsigned int have = (((unsigned int *)__s)[-1] & HX_GC_CONST_ALLOC_BIT) ? - ((unsigned int *)__s)[-2] : *((unsigned int *)(__s+length+1) ); + unsigned int have = (((unsigned int *)__s)[-1] & HX_GC_CONST_ALLOC_BIT) ? ((unsigned int *)__s)[-2] : + isUTF16Encoded() ? *((unsigned int *)(__w+length+1)) : *((unsigned int *)(__s+length+1)); if ( have != result ) { @@ -247,6 +247,13 @@ class HXCPP_EXTERN_CLASS_ATTRIBUTES String return ((unsigned int *)__s)[-2]; #endif } + if (isUTF16Encoded()) { + #ifdef __EMSCRIPTEN__ + return *((emscripten_align1_int *)(__w+length+1)); + #else + return *((unsigned int *)(__w+length+1)); + #endif + } #ifdef __EMSCRIPTEN__ return *((emscripten_align1_int *)(__s+length+1) ); #else diff --git a/src/String.cpp b/src/String.cpp index 4d84b77b7..dd0cbca22 100644 --- a/src/String.cpp +++ b/src/String.cpp @@ -932,9 +932,10 @@ unsigned int String::calcSubHash(int start, int inLen) const if (isUTF16Encoded()) { const char16_t *w = __w + start; - for(int i=0;i(); + m[literal] = 1; + + Assert.isTrue(m.exists(literal)); + Assert.isTrue(m.exists(fromJson)); + Assert.isTrue(m.exists(fromBytes)); + + Assert.equals(1, m[literal]); + Assert.equals(1, m[fromJson]); + Assert.equals(1, m[fromBytes]); + } + } }