diff options
author | Anna Henningsen <anna@addaleax.net> | 2019-03-19 18:18:22 +0100 |
---|---|---|
committer | Anna Henningsen <anna@addaleax.net> | 2019-03-26 14:48:56 +0100 |
commit | 3018441304697fe801fc81385229b5a78a62cc54 (patch) | |
tree | 22d9083a71267574f34a2913a59fe13c6bc564a7 /src/base_object-inl.h | |
parent | 53ebd3311d4e0ef184a062b2f657ac69dc8a7acf (diff) | |
download | android-node-v8-3018441304697fe801fc81385229b5a78a62cc54.tar.gz android-node-v8-3018441304697fe801fc81385229b5a78a62cc54.tar.bz2 android-node-v8-3018441304697fe801fc81385229b5a78a62cc54.zip |
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/base_object-inl.h')
-rw-r--r-- | src/base_object-inl.h | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/src/base_object-inl.h b/src/base_object-inl.h index f1f1498e6c..e3d645056a 100644 --- a/src/base_object-inl.h +++ b/src/base_object-inl.h @@ -123,6 +123,22 @@ BaseObject::MakeLazilyInitializedJSTemplate(Environment* env) { return t; } +template <int Field> +void BaseObject::InternalFieldGet( + v8::Local<v8::String> property, + const v8::PropertyCallbackInfo<v8::Value>& info) { + info.GetReturnValue().Set(info.This()->GetInternalField(Field)); +} + +template <int Field, bool (v8::Value::* typecheck)() const> +void BaseObject::InternalFieldSet(v8::Local<v8::String> property, + v8::Local<v8::Value> value, + const v8::PropertyCallbackInfo<void>& info) { + // This could be e.g. value->IsFunction(). + CHECK(((*value)->*typecheck)()); + info.This()->SetInternalField(Field, value); +} + } // namespace node #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS |