fs: dispatch ASCII and Latin1 via simdutf in ReadFileUtf8 by mertcanaltin · Pull Request #63370 · nodejs/node · GitHub
Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
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
62 changes: 62 additions & 0 deletions benchmark/fs/readfile-utf8-fastpath.js
16 changes: 0 additions & 16 deletions src/util-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -341,22 +341,6 @@ v8::Maybe<void> FromV8Array(v8::Local<v8::Context> context,
return js_array->Iterate(context, PushItemToVector, &data);
}

v8::MaybeLocal<v8::Value> ToV8Value(v8::Local<v8::Context> context,
std::string_view str,
v8::Isolate* isolate) {
if (isolate == nullptr) isolate = v8::Isolate::GetCurrent();
if (str.size() >= static_cast<size_t>(v8::String::kMaxLength)) [[unlikely]] {
// V8 only has a TODO comment about adding an exception when the maximum
// string size is exceeded.
ThrowErrStringTooLong(isolate);
return v8::MaybeLocal<v8::Value>();
}

return v8::String::NewFromUtf8(
isolate, str.data(), v8::NewStringType::kNormal, str.size())
.FromMaybe(v8::Local<v8::String>());
}

v8::MaybeLocal<v8::Value> ToV8Value(v8::Local<v8::Context> context,
std::u16string_view str,
v8::Isolate* isolate) {
Expand Down
11 changes: 11 additions & 0 deletions src/util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -812,4 +812,15 @@ v8::Maybe<int> GetValidFileMode(Environment* env,
return v8::Just(mode);
}

v8::MaybeLocal<v8::Value> ToV8Value(v8::Local<v8::Context> context,
std::string_view str,
v8::Isolate* isolate) {
if (isolate == nullptr) isolate = v8::Isolate::GetCurrent();
if (str.size() >= static_cast<size_t>(v8::String::kMaxLength)) [[unlikely]] {
ThrowErrStringTooLong(isolate);
return v8::MaybeLocal<v8::Value>();
}
return StringBytes::Encode(isolate, str.data(), str.size(), UTF8);
}

} // namespace node
6 changes: 3 additions & 3 deletions src/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -701,9 +701,9 @@ inline v8::Maybe<void> FromV8Array(v8::Local<v8::Context> context,
v8::Local<v8::Array> js_array,
std::vector<v8::Global<v8::Value>>* out);

inline v8::MaybeLocal<v8::Value> ToV8Value(v8::Local<v8::Context> context,
std::string_view str,
v8::Isolate* isolate = nullptr);
v8::MaybeLocal<v8::Value> ToV8Value(v8::Local<v8::Context> context,
std::string_view str,
v8::Isolate* isolate = nullptr);
inline v8::MaybeLocal<v8::Value> ToV8Value(v8::Local<v8::Context> context,
std::u16string_view str,
v8::Isolate* isolate = nullptr);
Expand Down
103 changes: 103 additions & 0 deletions test/parallel/test-fs-readfile-utf8-fast-path.js
Loading