File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1818#include < kj/refcount.h>
1919#include < kj/vector.h>
2020
21+ // Niche value optimization for v8::TracedReference<T>. This teaches kj::Maybe to use
22+ // TracedReference's built-in empty state (IsEmpty()) as the "none" representation, eliminating
23+ // the extra bool + alignment padding that kj::Maybe normally adds. This saves 8 bytes per
24+ // Maybe<TracedReference<T>> instance while preserving full type safety.
25+ namespace kj {
26+ template <typename T>
27+ struct MaybeTraits <v8::TracedReference<T>> {
28+ static void initNone (v8::TracedReference<T>* ptr) noexcept {
29+ ctor (*ptr);
30+ }
31+ static bool isNone (const v8::TracedReference<T>& ref) noexcept {
32+ return ref.IsEmpty ();
33+ }
34+ static constexpr bool noneIsMoveSafe = true ;
35+ };
36+ } // namespace kj
37+
2138namespace cppgc {
2239class Visitor ;
2340}
You can’t perform that action at this time.
0 commit comments