diff options
author | Anna Henningsen <anna@addaleax.net> | 2019-03-19 20:18:22 +0300 |
---|---|---|
committer | Anna Henningsen <anna@addaleax.net> | 2019-03-26 16:48:56 +0300 |
commit | 3018441304697fe801fc81385229b5a78a62cc54 (patch) | |
tree | 22d9083a71267574f34a2913a59fe13c6bc564a7 /src/stream_base.cc | |
parent | 53ebd3311d4e0ef184a062b2f657ac69dc8a7acf (diff) |
src: store onread callback in internal field
This gives a slight performance improvement. At 2000 runs:
confidence improvement accuracy (*) (**) (***)
net/net-c2s.js dur=5 type='buf' len=64 *** 0.54 % ±0.16% ±0.21% ±0.27%
PR-URL: https://github.com/nodejs/node/pull/26837
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Diffstat (limited to 'src/stream_base.cc')
-rw-r--r-- | src/stream_base.cc | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/src/stream_base.cc b/src/stream_base.cc index 3874d2d9af0..310e490f052 100644 --- a/src/stream_base.cc +++ b/src/stream_base.cc @@ -21,6 +21,7 @@ using v8::Context; using v8::DontDelete; using v8::DontEnum; using v8::External; +using v8::Function; using v8::FunctionCallbackInfo; using v8::HandleScope; using v8::Integer; @@ -314,7 +315,9 @@ void StreamBase::CallJSOnreadMethod(ssize_t nread, AsyncWrap* wrap = GetAsyncWrap(); CHECK_NOT_NULL(wrap); - wrap->MakeCallback(env->onread_string(), arraysize(argv), argv); + Local<Value> onread = wrap->object()->GetInternalField(kOnReadFunctionField); + CHECK(onread->IsFunction()); + wrap->MakeCallback(onread.As<Function>(), arraysize(argv), argv); } @@ -376,6 +379,10 @@ void StreamBase::AddMethods(Environment* env, Local<FunctionTemplate> t) { t->PrototypeTemplate()->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "isStreamBase"), True(env->isolate())); + t->PrototypeTemplate()->SetAccessor( + FIXED_ONE_BYTE_STRING(env->isolate(), "onread"), + BaseObject::InternalFieldGet<kOnReadFunctionField>, + BaseObject::InternalFieldSet<kOnReadFunctionField, &Value::IsFunction>); } void StreamBase::GetFD(const FunctionCallbackInfo<Value>& args) { |