From 4e6ff5eba7a71b803f3c46126e83ab7952464516 Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Sat, 27 Feb 2021 20:06:44 +0100 Subject: [PATCH] src: make BaseObject::is_snapshotable virtual 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. --- 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 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 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 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_; }