mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-05-04 18:38:05 +00:00
Convert StringMapEntry::Create to use StringRef instead of start/end pointers. Simpliies all in tree call sites. No functional change.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@210638 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
e12b0bbc02
commit
27be15cd36
@ -139,10 +139,10 @@ public:
|
|||||||
/// Create - Create a StringMapEntry for the specified key and default
|
/// Create - Create a StringMapEntry for the specified key and default
|
||||||
/// construct the value.
|
/// construct the value.
|
||||||
template<typename AllocatorTy, typename InitType>
|
template<typename AllocatorTy, typename InitType>
|
||||||
static StringMapEntry *Create(const char *KeyStart, const char *KeyEnd,
|
static StringMapEntry *Create(StringRef Key,
|
||||||
AllocatorTy &Allocator,
|
AllocatorTy &Allocator,
|
||||||
InitType InitVal) {
|
InitType InitVal) {
|
||||||
unsigned KeyLength = static_cast<unsigned>(KeyEnd-KeyStart);
|
unsigned KeyLength = Key.size();
|
||||||
|
|
||||||
// Allocate a new item with space for the string at the end and a null
|
// Allocate a new item with space for the string at the end and a null
|
||||||
// terminator.
|
// terminator.
|
||||||
@ -158,27 +158,25 @@ public:
|
|||||||
|
|
||||||
// Copy the string information.
|
// Copy the string information.
|
||||||
char *StrBuffer = const_cast<char*>(NewItem->getKeyData());
|
char *StrBuffer = const_cast<char*>(NewItem->getKeyData());
|
||||||
memcpy(StrBuffer, KeyStart, KeyLength);
|
memcpy(StrBuffer, Key.data(), KeyLength);
|
||||||
StrBuffer[KeyLength] = 0; // Null terminate for convenience of clients.
|
StrBuffer[KeyLength] = 0; // Null terminate for convenience of clients.
|
||||||
return NewItem;
|
return NewItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename AllocatorTy>
|
template<typename AllocatorTy>
|
||||||
static StringMapEntry *Create(const char *KeyStart, const char *KeyEnd,
|
static StringMapEntry *Create(StringRef Key, AllocatorTy &Allocator) {
|
||||||
AllocatorTy &Allocator) {
|
return Create(Key, Allocator, ValueTy());
|
||||||
return Create(KeyStart, KeyEnd, Allocator, 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create - Create a StringMapEntry with normal malloc/free.
|
/// Create - Create a StringMapEntry with normal malloc/free.
|
||||||
template<typename InitType>
|
template<typename InitType>
|
||||||
static StringMapEntry *Create(const char *KeyStart, const char *KeyEnd,
|
static StringMapEntry *Create(StringRef Key, InitType InitVal) {
|
||||||
InitType InitVal) {
|
|
||||||
MallocAllocator A;
|
MallocAllocator A;
|
||||||
return Create(KeyStart, KeyEnd, A, std::move(InitVal));
|
return Create(Key, A, std::move(InitVal));
|
||||||
}
|
}
|
||||||
|
|
||||||
static StringMapEntry *Create(const char *KeyStart, const char *KeyEnd) {
|
static StringMapEntry *Create(StringRef Key) {
|
||||||
return Create(KeyStart, KeyEnd, ValueTy());
|
return Create(Key, ValueTy());
|
||||||
}
|
}
|
||||||
|
|
||||||
/// GetStringMapEntryFromValue - Given a value that is known to be embedded
|
/// GetStringMapEntryFromValue - Given a value that is known to be embedded
|
||||||
@ -353,8 +351,7 @@ public:
|
|||||||
if (Bucket && Bucket != getTombstoneVal())
|
if (Bucket && Bucket != getTombstoneVal())
|
||||||
return *static_cast<MapEntryTy*>(Bucket);
|
return *static_cast<MapEntryTy*>(Bucket);
|
||||||
|
|
||||||
MapEntryTy *NewItem =
|
MapEntryTy *NewItem = MapEntryTy::Create(Key, Allocator, std::move(Val));
|
||||||
MapEntryTy::Create(Key.begin(), Key.end(), Allocator, std::move(Val));
|
|
||||||
|
|
||||||
if (Bucket == getTombstoneVal())
|
if (Bucket == getTombstoneVal())
|
||||||
--NumTombstones;
|
--NumTombstones;
|
||||||
|
@ -213,7 +213,7 @@ void Value::setName(const Twine &NewName) {
|
|||||||
// then reallocated.
|
// then reallocated.
|
||||||
|
|
||||||
// Create the new name.
|
// Create the new name.
|
||||||
Name = ValueName::Create(NameRef.begin(), NameRef.end());
|
Name = ValueName::Create(NameRef);
|
||||||
Name->setValue(this);
|
Name->setValue(this);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -27,7 +27,7 @@ PooledStringPtr StringPool::intern(StringRef Key) {
|
|||||||
if (I != InternTable.end())
|
if (I != InternTable.end())
|
||||||
return PooledStringPtr(&*I);
|
return PooledStringPtr(&*I);
|
||||||
|
|
||||||
entry_t *S = entry_t::Create(Key.begin(), Key.end());
|
entry_t *S = entry_t::Create(Key);
|
||||||
S->getValue().Pool = this;
|
S->getValue().Pool = this;
|
||||||
InternTable.insert(S);
|
InternTable.insert(S);
|
||||||
|
|
||||||
|
@ -187,7 +187,7 @@ TEST_F(StringMapTest, IterationTest) {
|
|||||||
TEST_F(StringMapTest, StringMapEntryTest) {
|
TEST_F(StringMapTest, StringMapEntryTest) {
|
||||||
StringMap<uint32_t>::value_type* entry =
|
StringMap<uint32_t>::value_type* entry =
|
||||||
StringMap<uint32_t>::value_type::Create(
|
StringMap<uint32_t>::value_type::Create(
|
||||||
testKeyFirst, testKeyFirst + testKeyLength, 1u);
|
StringRef(testKeyFirst, testKeyLength), 1u);
|
||||||
EXPECT_STREQ(testKey, entry->first().data());
|
EXPECT_STREQ(testKey, entry->first().data());
|
||||||
EXPECT_EQ(1u, entry->second);
|
EXPECT_EQ(1u, entry->second);
|
||||||
free(entry);
|
free(entry);
|
||||||
@ -198,7 +198,7 @@ TEST_F(StringMapTest, InsertTest) {
|
|||||||
SCOPED_TRACE("InsertTest");
|
SCOPED_TRACE("InsertTest");
|
||||||
testMap.insert(
|
testMap.insert(
|
||||||
StringMap<uint32_t>::value_type::Create(
|
StringMap<uint32_t>::value_type::Create(
|
||||||
testKeyFirst, testKeyFirst + testKeyLength,
|
StringRef(testKeyFirst, testKeyLength),
|
||||||
testMap.getAllocator(), 1u));
|
testMap.getAllocator(), 1u));
|
||||||
assertSingleItemMap();
|
assertSingleItemMap();
|
||||||
}
|
}
|
||||||
@ -236,7 +236,7 @@ TEST_F(StringMapTest, MoveOnlyKey) {
|
|||||||
StringMap<MoveOnly> t;
|
StringMap<MoveOnly> t;
|
||||||
t.GetOrCreateValue("Test", MoveOnly(42));
|
t.GetOrCreateValue("Test", MoveOnly(42));
|
||||||
StringRef Key = "Test";
|
StringRef Key = "Test";
|
||||||
StringMapEntry<MoveOnly>::Create(Key.begin(), Key.end(), MoveOnly(42))
|
StringMapEntry<MoveOnly>::Create(Key, MoveOnly(42))
|
||||||
->Destroy();
|
->Destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user