GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — buffer: improve byteLength performance · nodejs/node@dc22890

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • src
    • node_buffer.cc
    • node_external_reference.h
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎src/node_buffer.cc‎

Copy file name to clipboardExpand all lines: src/node_buffer.cc
+18-6Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -728,16 +728,28 @@ void SlowByteLengthUtf8(const FunctionCallbackInfo<Value>& args) {
728728
args.GetReturnValue().Set(args[0].As<String>()->Utf8Length(env->isolate()));
729729
}
730730

731-
uint32_t FastByteLengthUtf8(Local<Value> receiver,
732-
const v8::FastOneByteString& source) {
731+
uint32_t FastByteLengthUtf8(
732+
Local<Value> receiver,
733+
Local<Value> sourceValue,
734+
v8::FastApiCallbackOptions& options) { // NOLINT(runtime/references)
735+
TRACK_V8_FAST_API_CALL("Buffer::FastByteLengthUtf8");
736+
auto isolate = options.isolate;
737+
HandleScope handleScope(isolate);
738+
CHECK(sourceValue->IsString());
739+
Local<String> sourceStr = sourceValue.As<String>();
740+
741+
if (!sourceStr->IsExternalOneByte()) {
742+
return sourceStr->Utf8Length(isolate);
743+
}
744+
auto source = sourceStr->GetExternalOneByteStringResource();
733745
// For short inputs, the function call overhead to simdutf is maybe
734746
// not worth it, reserve simdutf for long strings.
735-
if (source.length > 128) {
736-
return simdutf::utf8_length_from_latin1(source.data, source.length);
747+
if (source->length() > 128) {
748+
return simdutf::utf8_length_from_latin1(source->data(), source->length());
737749
}
738750

739-
uint32_t length = source.length;
740-
const auto input = reinterpret_cast<const uint8_t*>(source.data);
751+
uint32_t length = source->length();
752+
const auto input = reinterpret_cast<const uint8_t*>(source->data());
741753

742754
uint32_t answer = length;
743755
uint32_t i = 0;
Collapse file

‎src/node_external_reference.h‎

Copy file name to clipboardExpand all lines: src/node_external_reference.h
+6Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ using CFunctionCallbackWithMultipleValueAndOptions =
1717
v8::Local<v8::Value>,
1818
v8::Local<v8::Value>,
1919
v8::FastApiCallbackOptions&);
20+
using CFunctionA =
21+
uint32_t (*)(v8::Local<v8::Value> receiver,
22+
v8::Local<v8::Value> sourceValue,
23+
// NOLINTNEXTLINE(runtime/references) This is V8 api.
24+
v8::FastApiCallbackOptions& options);
2025
using CFunctionCallbackWithOneByteString =
2126
uint32_t (*)(v8::Local<v8::Value>, const v8::FastOneByteString&);
2227

@@ -98,6 +103,7 @@ class ExternalReferenceRegistry {
98103
ExternalReferenceRegistry();
99104

100105
#define ALLOWED_EXTERNAL_REFERENCE_TYPES(V) \
106+
V(CFunctionA) \
101107
V(CFunctionCallback) \
102108
V(CFunctionCallbackWithalueAndOptions) \
103109
V(CFunctionCallbackWithMultipleValueAndOptions) \

0 commit comments

Comments
0 (0)
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.