Make NativeDataInfo handlers optional
Summary: In the case of SweepFunc, we can avoid adding
ourselves to the sweeplist entirely if there's no func.
I'm still allocating space for SweepNode atm, and I'd
like to fix that in a followup diff.
It probably means swapping the order of the NDI block
and the SweepNode block, otherwise Native::data ends up
looking like:
template<class T>
T* data(ObjectData *obj) {
if (obj->nativeDataInfo()->sweep) {
auto node = reinterpret_cast<SweepNode*>(obj) - 1;
return reinterpret_cast<T*>(node) - 1;
}
return reinterpret_cast<T*>(obj) - 1;
}
Which feels a lot more expensive for a relatively hot path.
If I do swap the order, then it simplifies down to just:
template<class T>
T* data(ObjectData *obj) {
return reinterpret_cast<T*>(obj) - 1;
}
and that's great for runtime, but Sweep gets weird since
SweepNode doesn't know where it's ObjectData* is relative
to itself.
I could make my own SweepNode struct which points at the
ObjectData* instead (which in turn knows how to map back
to the SweepNode), but that ends up looking like a weird
broken linked-list and takes longer to actually do the sweeps.
Or maybe it's fine to just leave those two extra pointer allocations.
Reviewed By: @jdelong
Differential Revision:
D1291769