11#include < hxcpp.h>
2- #include < array>
32#include < simdutf.h>
43#include < hx/thread/Scratch.hpp>
54
@@ -246,16 +245,16 @@ String cpp::encoding::Utf8::decode(const cpp::marshal::View<uint8_t>& buffer)
246245
247246char32_t cpp::encoding::Utf8::codepoint (const cpp::marshal::View<uint8_t >& buffer)
248247{
249- auto output = std::array< char32_t , 4 >( );
250- auto read = simdutf::convert_utf8_to_utf32 (reinterpret_cast <char *>(buffer.ptr .ptr ), std::min (int64_t { 4 } , buffer.length ), output.data ( ));
248+ auto output = hx::thread::Scratch::alloc ( sizeof ( char32_t ) * 4 );
249+ auto read = simdutf::convert_utf8_to_utf32 (reinterpret_cast <char *>(buffer.ptr .ptr ), std::min (output. view . length , buffer.length ), reinterpret_cast < char32_t *>( output.view . ptr . ptr ));
251250
252251 if (0 == read)
253252 {
254253 return int { hx::Throw (HX_CSTRING (" Failed to read codepoint" )) };
255254 }
256255 else
257256 {
258- return output[0 ];
257+ return reinterpret_cast < char32_t *>( output. view . ptr . ptr ) [0 ];
259258 }
260259}
261260
@@ -411,11 +410,11 @@ String cpp::encoding::Utf16::decode(const cpp::marshal::View<uint8_t>& buffer)
411410
412411char32_t cpp::encoding::Utf16::codepoint (const cpp::marshal::View<uint8_t >& buffer)
413412{
414- auto output = std::array< char32_t , 8 >( );
413+ auto output = hx::thread::Scratch::alloc ( sizeof ( char32_t ) * 4 );
415414#if defined(HXCPP_BIG_ENDIAN)
416- auto read = simdutf::convert_utf16be_to_utf32 (reinterpret_cast <char16_t *>(buffer.ptr .ptr ), std::min (int64_t { 4 } , buffer.length ), output.data ( ));
415+ auto read = simdutf::convert_utf16be_to_utf32 (reinterpret_cast <char16_t *>(buffer.ptr .ptr ), std::min (output. view . length , buffer.length ), reinterpret_cast < char32_t *>( output.view . ptr . ptr ));
417416#else
418- auto read = simdutf::convert_utf16le_to_utf32 (reinterpret_cast <char16_t *>(buffer.ptr .ptr ), std::min (int64_t { 4 } , buffer.length ), output.data ( ));
417+ auto read = simdutf::convert_utf16le_to_utf32 (reinterpret_cast <char16_t *>(buffer.ptr .ptr ), std::min (output. view . length , buffer.length ), reinterpret_cast < char32_t *>( output.view . ptr . ptr ));
419418#endif
420419
421420 if (0 == read)
@@ -424,6 +423,6 @@ char32_t cpp::encoding::Utf16::codepoint(const cpp::marshal::View<uint8_t>& buff
424423 }
425424 else
426425 {
427- return output[0 ];
426+ return reinterpret_cast < char32_t *>( output. view . ptr . ptr ) [0 ];
428427 }
429428}
0 commit comments