Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add old way for <= 32 length
  • Loading branch information
anonrig committed Nov 25, 2025
commit ee71c43d257ba19d8a911a02bb4ab5bb30478836
13 changes: 13 additions & 0 deletions src/encoding_binding.cc
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,19 @@ void BindingData::EncodeInto(const FunctionCallbackInfo<Value>& args) {
char* write_result = static_cast<char*>(buf->Data()) + dest->ByteOffset();
size_t dest_length = dest->ByteLength();

// For small strings (length <= 32), use the old V8 path for better performance
if (source->Length() <= 32) {
size_t nchars;
size_t written = source->WriteUtf8V2(isolate,
write_result,
dest_length,
String::WriteFlags::kReplaceInvalidUtf8,
&nchars);
binding_data->encode_into_results_buffer_[0] = nchars;
binding_data->encode_into_results_buffer_[1] = written;
return;
}

size_t read = 0;
size_t written = 0;
v8::String::ValueView view(isolate, source);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
v8::String::ValueView view(isolate, source);
// Note: Take care not to perform any action in v8 that would
// trigger GC as it could cause the view to become invalid.
v8::String::ValueView view(isolate, source);

Expand Down
Loading