Skip to content

Commit

Permalink
improve jsstring toarray performance
Browse files Browse the repository at this point in the history
  • Loading branch information
anonrig committed Oct 1, 2024
1 parent 38cbdaf commit 0d049d7
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/workerd/jsg/jsvalue.h
Original file line number Diff line number Diff line change
Expand Up @@ -433,8 +433,10 @@ inline kj::Array<T> JsString::toArray(Lock& js, WriteOptions options) const {
inner->WriteOneByte(js.v8Isolate, buf.begin(), 0, buf.size(), options);
return kj::mv(buf);
} else {
auto buf = kj::heapArray<uint16_t>(inner->Length());
inner->Write(js.v8Isolate, buf.begin(), 0, buf.size(), options);
v8::String::ValueView view(js.v8Isolate, inner);
KJ_ASSERT(!view.is_one_byte());
auto buf = kj::heapArray<uint16_t>(view.length());
memcpy(buf.begin(), view.data16(), view.length());
return kj::mv(buf);
}
}
Expand Down

0 comments on commit 0d049d7

Please sign in to comment.