-
Philip Chimento authored
In GjsMaybeOwned<T> the JS::Heap<T> and JS::PersistentRooted<T>* members are mutually exclusive. The m_rooted flag determines which one we are using. Therefore, we can put the two in a union to save space. The only thing we have to do is watch out when switching from one mode to the other. When switching to rooted, we have to be careful to call the destructor of JS::Heap, and when switching to unrooted we have to use placement-new to construct a JS::Heap in the location of the union. This reduces the size of ObjectInstance to 88 bytes on x86_64 (although when the GjsMaybeOwned is in rooted mode, that is, the ObjectInstance is in toggle ref mode and a GObject owns a reference to it, there are 32 "hidden" bytes allocated for the PersistentRooted.)
4e7f4a53