Skip to content

Commit ae132b9

Browse files
committed
Use realloc instead of allocChar16Ptr
1 parent ac49c6d commit ae132b9

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

src/cpp/encoding/Encodings.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -334,9 +334,9 @@ String cpp::encoding::Utf8::decode(const cpp::marshal::View<uint8_t>& buffer)
334334
return Ascii::decode(buffer);
335335
}
336336
#if defined(HX_SMART_STRINGS)
337-
auto estimated_length = buffer.length;
337+
auto estimated_length = buffer.length * sizeof(char16_t);
338338

339-
auto temp = ::String::allocChar16Ptr(estimated_length);
339+
auto temp = ::hx::InternalNew(estimated_length, false);
340340
auto output = View<char16_t>(temp, estimated_length).reinterpret<uint8_t>();
341341
int64_t k = 0;
342342
int64_t i = 0;
@@ -350,9 +350,10 @@ String cpp::encoding::Utf8::decode(const cpp::marshal::View<uint8_t>& buffer)
350350
}
351351

352352
auto chars = static_cast<int>(k / sizeof(char16_t));
353-
auto exact = ::String::allocChar16Ptr(chars);
354353

355-
std::memcpy(exact, temp, k);
354+
auto exact = static_cast<char16_t*>(::hx::InternalRealloc(estimated_length, temp, k + sizeof(char16_t)));
355+
((unsigned int*)exact)[-1] |= HX_GC_STRING_CHAR16_T;
356+
exact[chars] = 0;
356357

357358
return String(exact, chars);
358359
#else

0 commit comments

Comments
 (0)