File tree 1 file changed +14
-3
lines changed
1 file changed +14
-3
lines changed Original file line number Diff line number Diff line change 48
48
#include < sys/types.h>
49
49
#endif
50
50
51
+ #include < simdutf.h>
52
+
51
53
#include < atomic>
52
54
#include < cstdio>
53
55
#include < cstring>
@@ -100,11 +102,20 @@ static void MakeUtf8String(Isolate* isolate,
100
102
MaybeStackBuffer<T>* target) {
101
103
Local<String> string;
102
104
if (!value->ToString (isolate->GetCurrentContext ()).ToLocal (&string)) return ;
105
+ String::ValueView value_view (isolate, string);
103
106
104
- size_t storage;
105
- if (!StringBytes::StorageSize (isolate, string, UTF8).To (&storage)) return ;
106
- storage += 1 ;
107
+ if (value_view.is_one_byte ()) {
108
+ target->AllocateSufficientStorage (value_view.length () + 1 );
109
+ target->SetLengthAndZeroTerminate (value_view.length ());
110
+ memcpy (target->out (), reinterpret_cast <const char *>(value_view.data8 ()), value_view.length ());
111
+ return ;
112
+ }
113
+
114
+ // Add +1 for null termination.
115
+ auto storage = simdutf::utf8_length_from_utf16 (reinterpret_cast <const char16_t *>(value_view.data16 ()), value_view.length ()) + 1 ;
107
116
target->AllocateSufficientStorage (storage);
117
+
118
+ // TODO(@anonrig): Use simdutf to speed up non-one-byte strings once it's implemented
108
119
const int flags =
109
120
String::NO_NULL_TERMINATION | String::REPLACE_INVALID_UTF8;
110
121
const int length =
You can’t perform that action at this time.
0 commit comments