File tree 1 file changed +20
-3
lines changed
1 file changed +20
-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,26 @@ 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);
106
+
107
+ if (value_view.is_one_byte ()) {
108
+ target->AllocateSufficientStorage (value_view.length () + 1 );
109
+ target->SetLengthAndZeroTerminate (value_view.length ());
110
+ memcpy (target->out (),
111
+ reinterpret_cast <const char *>(value_view.data8 ()),
112
+ value_view.length ());
113
+ return ;
114
+ }
103
115
104
- size_t storage;
105
- if (!StringBytes::StorageSize (isolate, string, UTF8).To (&storage)) return ;
106
- storage += 1 ;
116
+ // Add +1 for null termination.
117
+ auto storage = simdutf::utf8_length_from_utf16 (
118
+ reinterpret_cast <const char16_t *>(value_view.data16 ()),
119
+ value_view.length ()) +
120
+ 1 ;
107
121
target->AllocateSufficientStorage (storage);
122
+
123
+ // TODO(@anonrig): Use simdutf to speed up non-one-byte strings once it's
124
+ // implemented
108
125
const int flags =
109
126
String::NO_NULL_TERMINATION | String::REPLACE_INVALID_UTF8;
110
127
const int length =
You can’t perform that action at this time.
0 commit comments