Skip to content

Commit

Permalink
src: make BaseObject::is_snapshotable virtual
Browse files Browse the repository at this point in the history
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: nodejs#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>
  • Loading branch information
addaleax committed Mar 3, 2021
1 parent 007a85c commit 3b2863d
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 4 deletions.
4 changes: 1 addition & 3 deletions src/base_object.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
Expand Down
1 change: 0 additions & 1 deletion src/node_snapshotable.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions src/node_snapshotable.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_; }

Expand Down

0 comments on commit 3b2863d

Please sign in to comment.