File tree Expand file tree Collapse file tree 1 file changed +15
-3
lines changed
Expand file tree Collapse file tree 1 file changed +15
-3
lines changed Original file line number Diff line number Diff line change @@ -34,8 +34,13 @@ struct OpaqueWrappableBase: public Wrappable {
3434 }
3535};
3636
37+ // We declare OpaqueWrappable<T> specializations here as final to allow the compiler
38+ // to optimize dynamic_cast<T*> to simply check if the vtable is equal to T's vtable.
39+ // This provides a minor performance improvement when interacting with opaque-wrapped
40+ // values.
41+
3742template <typename T>
38- struct OpaqueWrappable <T, false >: public OpaqueWrappableBase {
43+ struct OpaqueWrappable <T, false > final : public OpaqueWrappableBase {
3944 // Used to implement wrapOpaque().
4045
4146 OpaqueWrappable (T&& value): value(kj::mv(value)) {}
@@ -49,10 +54,17 @@ struct OpaqueWrappable<T, false>: public OpaqueWrappableBase {
4954};
5055
5156template <typename T>
52- struct OpaqueWrappable <T, true >: public OpaqueWrappable<T, false > {
57+ struct OpaqueWrappable <T, true > final : public OpaqueWrappableBase {
5358 // When T is GC-visitable, make sure to implement visitation.
5459
55- using OpaqueWrappable<T, false >::OpaqueWrappable;
60+ OpaqueWrappable (T&& value): value(kj::mv(value)) {}
61+
62+ T value;
63+ bool movedAway = false ;
64+
65+ size_t jsgGetMemorySelfSize () const override final {
66+ return sizeof (OpaqueWrappable);
67+ }
5668
5769 void jsgVisitForGc (GcVisitor& visitor) override {
5870 if (!this ->movedAway ) {
You can’t perform that action at this time.
0 commit comments