Skip to content

Commit 33436e3

Browse files
addaleaxdanielleadams
authored andcommitted
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. PR-URL: #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>
1 parent 8024ffb commit 33436e3

File tree

3 files changed

+2
-4
lines changed

3 files changed

+2
-4
lines changed

src/base_object.h

+1-3
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,7 @@ class BaseObject : public MemoryRetainer {
158158

159159
virtual inline void OnGCCollect();
160160

161-
bool is_snapshotable() const { return is_snapshotable_; }
162-
void set_is_snapshotable(bool val) { is_snapshotable_ = val; }
161+
virtual inline bool is_snapshotable() const { return false; }
163162

164163
private:
165164
v8::Local<v8::Object> WrappedObject() const override;
@@ -209,7 +208,6 @@ class BaseObject : public MemoryRetainer {
209208

210209
Environment* env_;
211210
PointerData* pointer_data_ = nullptr;
212-
bool is_snapshotable_ = false;
213211
};
214212

215213
// Global alias for FromJSObject() to avoid churn.

src/node_snapshotable.cc

-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ SnapshotableObject::SnapshotableObject(Environment* env,
1616
Local<Object> wrap,
1717
EmbedderObjectType type)
1818
: BaseObject(env, wrap), type_(type) {
19-
set_is_snapshotable(true);
2019
}
2120

2221
const char* SnapshotableObject::GetTypeNameChars() const {

src/node_snapshotable.h

+1
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ class SnapshotableObject : public BaseObject {
9090
virtual void PrepareForSerialization(v8::Local<v8::Context> context,
9191
v8::SnapshotCreator* creator) = 0;
9292
virtual InternalFieldInfo* Serialize(int index) = 0;
93+
bool is_snapshotable() const override { return true; }
9394
// We'll make sure that the type is set in the constructor
9495
EmbedderObjectType type() { return type_; }
9596

0 commit comments

Comments
 (0)