llvm.org GIT mirror llvm / b0439e6
StringMap support for move-only values. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@208359 91177308-0d34-0410-b5e6-96231b3b80d8 David Blaikie 5 years ago
2 changed file(s) with 21 addition(s) and 5 deletion(s). Raw diff Collapse all Expand all
108108
109109 explicit StringMapEntry(unsigned strLen)
110110 : StringMapEntryBase(strLen), second() {}
111 StringMapEntry(unsigned strLen, const ValueTy &V)
112 : StringMapEntryBase(strLen), second(V) {}
111 StringMapEntry(unsigned strLen, ValueTy V)
112 : StringMapEntryBase(strLen), second(std::move(V)) {}
113113
114114 StringRef getKey() const {
115115 return StringRef(getKeyData(), getKeyLength());
145145 static_cast(Allocator.Allocate(AllocSize,Alignment));
146146
147147 // Default construct the value.
148 new (NewItem) StringMapEntry(KeyLength, InitVal);
148 new (NewItem) StringMapEntry(KeyLength, std::move(InitVal));
149149
150150 // Copy the string information.
151151 char *StrBuffer = const_cast(NewItem->getKeyData());
165165 static StringMapEntry *Create(const char *KeyStart, const char *KeyEnd,
166166 InitType InitVal) {
167167 MallocAllocator A;
168 return Create(KeyStart, KeyEnd, A, InitVal);
168 return Create(KeyStart, KeyEnd, A, std::move(InitVal));
169169 }
170170
171171 static StringMapEntry *Create(const char *KeyStart, const char *KeyEnd) {
347347 return *static_cast(Bucket);
348348
349349 MapEntryTy *NewItem =
350 MapEntryTy::Create(Key.begin(), Key.end(), Allocator, Val);
350 MapEntryTy::Create(Key.begin(), Key.end(), Allocator, std::move(Val));
351351
352352 if (Bucket == getTombstoneVal())
353353 --NumTombstones;
217217 ASSERT_EQ(iter->second.i, 123);
218218 }
219219
220 struct MoveOnly {
221 int i;
222 MoveOnly(int i) : i(i) {}
223 MoveOnly(MoveOnly&&) = default;
224 MoveOnly(const MoveOnly&) = delete;
225 MoveOnly &operator=(MoveOnly&&) = default;
226 MoveOnly &operator=(const MoveOnly&) = delete;
227 };
228
229 TEST_F(StringMapTest, MoveOnlyKey) {
230 StringMap t;
231 t.GetOrCreateValue("Test", MoveOnly(42));
232 StringRef Key = "Test";
233 StringMapEntry::Create(Key.begin(), Key.end(), MoveOnly(42))->Destroy();
234 }
235
220236 } // end anonymous namespace