[PATCH] D100387: Simplify BitVector code
Nikita Popov via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Apr 13 14:53:30 PDT 2021
nikic accepted this revision.
nikic added a comment.
This revision is now accepted and ready to land.
LGTM
================
Comment at: llvm/include/llvm/ADT/BitVector.h:667
- // Handle tombstone when the BitVector is a key of a DenseHash.
- if (RHS.isInvalid()) {
- std::free(Bits.data());
- Bits = None;
- return *this;
- }
-
- unsigned RHSWords = NumBitWords(Size);
- if (Size <= getBitCapacity()) {
- if (Size)
- std::memcpy(Bits.data(), RHS.Bits.data(), RHSWords * sizeof(BitWord));
- clear_unused_bits();
- return *this;
- }
-
- // Grow the bitvector to have enough elements.
- unsigned NewCapacity = RHSWords;
- assert(NewCapacity > 0 && "negative capacity?");
- auto NewBits = allocate(NewCapacity);
- std::memcpy(NewBits.data(), RHS.Bits.data(), NewCapacity * sizeof(BitWord));
-
- // Destroy the old bits.
- std::free(Bits.data());
- Bits = NewBits;
-
- return *this;
- }
-
- const BitVector &operator=(BitVector &&RHS) {
- if (this == &RHS) return *this;
-
- std::free(Bits.data());
- Bits = RHS.Bits;
- Size = RHS.Size;
-
- RHS.Bits = MutableArrayRef<BitWord>();
- RHS.Size = 0;
-
- return *this;
- }
+ BitVector &operator=(BitVector &&RHS) = default;
----------------
I'd move these next to the copy/move constructors ... though actually, can we just drop all of these? I don't think the explicit defaulting is necessary in this instance.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D100387/new/
https://reviews.llvm.org/D100387
More information about the llvm-commits
mailing list