#include "llvm/ADT/StringRef.h"
#include "llvm/Support/Allocator.h"
#include <cstring>
+#include <utility>
namespace llvm {
template<typename ValueT>
unsigned NumTombstones;
unsigned ItemSize;
protected:
- explicit StringMapImpl(unsigned itemSize) : ItemSize(itemSize) {
- // Initialize the map with zero buckets to allocation.
- TheTable = nullptr;
- NumBuckets = 0;
- NumItems = 0;
- NumTombstones = 0;
+ explicit StringMapImpl(unsigned itemSize)
+ : TheTable(nullptr),
+ // Initialize the map with zero buckets to allocation.
+ NumBuckets(0), NumItems(0), NumTombstones(0), ItemSize(itemSize) {}
+ StringMapImpl(StringMapImpl &&RHS)
+ : TheTable(RHS.TheTable), NumBuckets(RHS.NumBuckets),
+ NumItems(RHS.NumItems), NumTombstones(RHS.NumTombstones),
+ ItemSize(RHS.ItemSize) {
+ RHS.TheTable = nullptr;
+ RHS.NumBuckets = 0;
+ RHS.NumItems = 0;
+ RHS.NumTombstones = 0;
}
+
StringMapImpl(unsigned InitSize, unsigned ItemSize);
void RehashTable();
explicit StringMapEntry(unsigned strLen)
: StringMapEntryBase(strLen), second() {}
StringMapEntry(unsigned strLen, ValueTy V)
- : StringMapEntryBase(strLen), second(std::move(V)) {}
+ : StringMapEntryBase(strLen), second(std::move(V)) {}
StringRef getKey() const {
return StringRef(getKeyData(), getKeyLength());
: StringMapImpl(InitialSize, static_cast<unsigned>(sizeof(MapEntryTy))),
Allocator(A) {}
- StringMap(const StringMap &RHS)
- : StringMapImpl(static_cast<unsigned>(sizeof(MapEntryTy))) {
- assert(RHS.empty() &&
- "Copy ctor from non-empty stringmap not implemented yet!");
- (void)RHS;
- }
- void operator=(const StringMap &RHS) {
- assert(RHS.empty() &&
- "assignment from non-empty stringmap not implemented yet!");
- (void)RHS;
- clear();
+ StringMap(StringMap &&RHS)
+ : StringMapImpl(std::move(RHS)), Allocator(std::move(RHS.Allocator)) {}
+
+ StringMap &operator=(StringMap RHS) {
+ StringMapImpl::swap(RHS);
+ std::swap(Allocator, RHS.Allocator);
+ return *this;
}
+ // FIXME: Implement copy operations if/when they're needed.
+
AllocatorTy &getAllocator() { return Allocator; }
const AllocatorTy &getAllocator() const { return Allocator; }
return *static_cast<MapEntryTy*>(Bucket);
MapEntryTy *NewItem =
- MapEntryTy::Create(Key.begin(), Key.end(), Allocator, std::move(Val));
+ MapEntryTy::Create(Key.begin(), Key.end(), Allocator, std::move(Val));
if (Bucket == getTombstoneVal())
--NumTombstones;