And update the unittest.
These changes will be used by an upcoming patch.
Differential D136242
[IntervalMap] Add move and copy ctors and assignment operators Orlando on Oct 19 2022, 3:42 AM. Authored by
Details And update the unittest. These changes will be used by an upcoming patch.
Diff Detail Event TimelineComment Actions Sounds good
Comment Actions Thanks @dblaikie. I was about to land this and noticed some potential UB - I have put a question inline.
Comment Actions It turns out my base commit was old and was missing some changes. Notably, the AlignedCharArrayUnion<RootLeaf, RootBranchData> data member has since been replaced with a union. Apologies for the noise and additional review required as a result. Due to the use of an anonymous union and the already tangled object lifetime situation I've changed from using the std::swap idiom, opting for instead explicitly cleaning up the moved-into object before the move (see destroyTree and createTree). No issues are reported when running the unittest built with -fsanitize=address,undefined (are there any other sanitizers I should be using?).
Comment Actions This is somewhat fiddly - I think I've got it this time though. I have used forwarding constructors this time. There's a gottcha - the move/copy constructors set the allocator field before calling the assignment operator, which calls clear. If the IntervalMap constructor was ever changed to allocate nodes then that clear call would deallocate using the wrong allocator. I've added an assertion to the move/copy constructors to help catch this. I've slightly updated the test (see the inline comment). I've added a few comments this time round, including a method group docu-comment explaining a requirement of the lifetime of the allocator of RHS.
Comment Actions That all looks about right to me.
|
could drop the height and rootSize initializations now that they're initialized at the member declaration