We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent c696b23 commit ecc950fCopy full SHA for ecc950f
1 file changed
src/cpp/encoding/Encodings.cpp
@@ -249,7 +249,8 @@ Array<uint8_t> cpp::encoding::Utf8::encode(const String& string)
249
}
250
251
#if defined(HX_SMART_STRINGS)
252
- Array<uint8_t> out(getByteCount(string), 0);
+ // estimate the utf8 length with an upper bound
253
+ Array<uint8_t> out(string.length * 3, 0);
254
View<uint8_t> buffer(out->Pointer(), out->length);
255
256
auto initialPtr = buffer.ptr.ptr;
@@ -265,6 +266,8 @@ Array<uint8_t> cpp::encoding::Utf8::encode(const String& string)
265
266
k += encode(p, buffer.slice(k));
267
268
269
+ out->resize(i);
270
+
271
return out;
272
#else
273
return hx::Throw(HX_CSTRING("Unexpected encoding error"));
0 commit comments