From 33436e39fe77d22d4a1955a5940d8e0113fb8487 Mon Sep 17 00:00:00 2001 From: Anna Henningsen <anna@addaleax.net> Date: Sat, 27 Feb 2021 20:06:44 +0100 Subject: [PATCH] src: make BaseObject::is_snapshotable virtual MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Use a virtual function in order to save space (8 bytes per instance on 64-bit platforms) and in order to be consistent with the other methods on BaseObject. PR-URL: https://github.com/nodejs/node/pull/37539 Reviewed-By: Gerhard Stöbich <deb2001-github@yahoo.de> Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: Darshan Sen <raisinten@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> --- src/base_object.h | 4 +--- src/node_snapshotable.cc | 1 - src/node_snapshotable.h | 1 + 3 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/base_object.h b/src/base_object.h index 6482bd85f86a56..05b5704f8fbf65 100644 --- a/src/base_object.h +++ b/src/base_object.h @@ -158,8 +158,7 @@ class BaseObject : public MemoryRetainer { virtual inline void OnGCCollect(); - bool is_snapshotable() const { return is_snapshotable_; } - void set_is_snapshotable(bool val) { is_snapshotable_ = val; } + virtual inline bool is_snapshotable() const { return false; } private: v8::Local<v8::Object> WrappedObject() const override; @@ -209,7 +208,6 @@ class BaseObject : public MemoryRetainer { Environment* env_; PointerData* pointer_data_ = nullptr; - bool is_snapshotable_ = false; }; // Global alias for FromJSObject() to avoid churn. diff --git a/src/node_snapshotable.cc b/src/node_snapshotable.cc index 04ae6e26131b4e..216a0a9a72536f 100644 --- a/src/node_snapshotable.cc +++ b/src/node_snapshotable.cc @@ -16,7 +16,6 @@ SnapshotableObject::SnapshotableObject(Environment* env, Local<Object> wrap, EmbedderObjectType type) : BaseObject(env, wrap), type_(type) { - set_is_snapshotable(true); } const char* SnapshotableObject::GetTypeNameChars() const { diff --git a/src/node_snapshotable.h b/src/node_snapshotable.h index 04277ff5378e33..c3b82c6edc71e9 100644 --- a/src/node_snapshotable.h +++ b/src/node_snapshotable.h @@ -90,6 +90,7 @@ class SnapshotableObject : public BaseObject { virtual void PrepareForSerialization(v8::Local<v8::Context> context, v8::SnapshotCreator* creator) = 0; virtual InternalFieldInfo* Serialize(int index) = 0; + bool is_snapshotable() const override { return true; } // We'll make sure that the type is set in the constructor EmbedderObjectType type() { return type_; }