Branch: refs/heads/main
Home: https://github.com/WebKit/WebKit
Commit: 6b907580f29ee7928bdb47b3addcafe6273ec3b3
https://github.com/WebKit/WebKit/commit/6b907580f29ee7928bdb47b3addcafe6273ec3b3
Author: Chris Dumez <[email protected]>
Date: 2026-03-27 (Fri, 27 Mar 2026)
Changed paths:
M Source/WTF/wtf/BitVector.h
M Tools/TestWebKitAPI/Tests/WTF/BitVector.cpp
Log Message:
-----------
Add move constructor and move assignment operator to BitVector
https://bugs.webkit.org/show_bug.cgi?id=310857
Reviewed by Ryosuke Niwa.
BitVector's out-of-line representation heap-allocates an OutOfLineBits
struct. Without move semantics, every copy of an out-of-line BitVector
triggers a new allocation + memcpy, even when the source is a temporary
or is being explicitly moved from via WTF::move().
Several call sites already use WTF:move() with BitVector (e.g.
BytecodeGenerator::addBitVector, LikelyDenseUnsignedIntegerSet,
UnlinkedCodeBlockGenerator), but these silently fall back to copying
since no move operations are defined. Storing BitVectors in Vector<>
and FixedVector<> also means copies during reallocation where moves
would suffice.
The implementation is trivial: steal the source's m_bitsOrPointer and
leave it as an empty inline vector via std::exchange. For inline
BitVectors (<=63 bits) this is equivalent to a copy; for out-of-line
ones it avoids a heap allocation and deallocation entirely.
Test: Tools/TestWebKitAPI/Tests/WTF/BitVector.cpp
* Source/WTF/wtf/BitVector.h:
* Tools/TestWebKitAPI/Tests/WTF/BitVector.cpp:
(TestWebKitAPI::TEST(WTF_BitVector, MoveConstructInline)):
(TestWebKitAPI::TEST(WTF_BitVector, MoveConstructOutOfLine)):
(TestWebKitAPI::TEST(WTF_BitVector, MoveAssignInline)):
(TestWebKitAPI::TEST(WTF_BitVector, MoveAssignOutOfLine)):
(TestWebKitAPI::TEST(WTF_BitVector, MoveAssignOutOfLineToOutOfLine)):
(TestWebKitAPI::TEST(WTF_BitVector, MoveInVector)):
(TestWebKitAPI::TEST(WTF_BitVector, MoveAssignSelf)):
Canonical link: https://commits.webkit.org/310057@main
To unsubscribe from these emails, change your notification settings at
https://github.com/WebKit/WebKit/settings/notifications