diff --git a/include/llvm/ADT/StringMap.h b/include/llvm/ADT/StringMap.h index ecac5dd5f66..5b186818798 100644 --- a/include/llvm/ADT/StringMap.h +++ b/include/llvm/ADT/StringMap.h @@ -139,10 +139,10 @@ public: /// Create - Create a StringMapEntry for the specified key and default /// construct the value. template - static StringMapEntry *Create(const char *KeyStart, const char *KeyEnd, + static StringMapEntry *Create(StringRef Key, AllocatorTy &Allocator, InitType InitVal) { - unsigned KeyLength = static_cast(KeyEnd-KeyStart); + unsigned KeyLength = Key.size(); // Allocate a new item with space for the string at the end and a null // terminator. @@ -158,27 +158,25 @@ public: // Copy the string information. char *StrBuffer = const_cast(NewItem->getKeyData()); - memcpy(StrBuffer, KeyStart, KeyLength); + memcpy(StrBuffer, Key.data(), KeyLength); StrBuffer[KeyLength] = 0; // Null terminate for convenience of clients. return NewItem; } template - static StringMapEntry *Create(const char *KeyStart, const char *KeyEnd, - AllocatorTy &Allocator) { - return Create(KeyStart, KeyEnd, Allocator, 0); + static StringMapEntry *Create(StringRef Key, AllocatorTy &Allocator) { + return Create(Key, Allocator, ValueTy()); } /// Create - Create a StringMapEntry with normal malloc/free. template - static StringMapEntry *Create(const char *KeyStart, const char *KeyEnd, - InitType InitVal) { + static StringMapEntry *Create(StringRef Key, InitType InitVal) { 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) { - return Create(KeyStart, KeyEnd, ValueTy()); + static StringMapEntry *Create(StringRef Key) { + return Create(Key, ValueTy()); } /// GetStringMapEntryFromValue - Given a value that is known to be embedded @@ -353,8 +351,7 @@ public: if (Bucket && Bucket != getTombstoneVal()) return *static_cast(Bucket); - MapEntryTy *NewItem = - MapEntryTy::Create(Key.begin(), Key.end(), Allocator, std::move(Val)); + MapEntryTy *NewItem = MapEntryTy::Create(Key, Allocator, std::move(Val)); if (Bucket == getTombstoneVal()) --NumTombstones; diff --git a/lib/IR/Value.cpp b/lib/IR/Value.cpp index f392512c3e9..463024a28c7 100644 --- a/lib/IR/Value.cpp +++ b/lib/IR/Value.cpp @@ -213,7 +213,7 @@ void Value::setName(const Twine &NewName) { // then reallocated. // Create the new name. - Name = ValueName::Create(NameRef.begin(), NameRef.end()); + Name = ValueName::Create(NameRef); Name->setValue(this); return; } diff --git a/lib/Support/StringPool.cpp b/lib/Support/StringPool.cpp index ff607cf8c4a..76faabc92bb 100644 --- a/lib/Support/StringPool.cpp +++ b/lib/Support/StringPool.cpp @@ -27,7 +27,7 @@ PooledStringPtr StringPool::intern(StringRef Key) { if (I != InternTable.end()) return PooledStringPtr(&*I); - entry_t *S = entry_t::Create(Key.begin(), Key.end()); + entry_t *S = entry_t::Create(Key); S->getValue().Pool = this; InternTable.insert(S); diff --git a/unittests/ADT/StringMapTest.cpp b/unittests/ADT/StringMapTest.cpp index de18e07f386..70eec873ed2 100644 --- a/unittests/ADT/StringMapTest.cpp +++ b/unittests/ADT/StringMapTest.cpp @@ -187,7 +187,7 @@ TEST_F(StringMapTest, IterationTest) { TEST_F(StringMapTest, StringMapEntryTest) { StringMap::value_type* entry = StringMap::value_type::Create( - testKeyFirst, testKeyFirst + testKeyLength, 1u); + StringRef(testKeyFirst, testKeyLength), 1u); EXPECT_STREQ(testKey, entry->first().data()); EXPECT_EQ(1u, entry->second); free(entry); @@ -198,7 +198,7 @@ TEST_F(StringMapTest, InsertTest) { SCOPED_TRACE("InsertTest"); testMap.insert( StringMap::value_type::Create( - testKeyFirst, testKeyFirst + testKeyLength, + StringRef(testKeyFirst, testKeyLength), testMap.getAllocator(), 1u)); assertSingleItemMap(); } @@ -236,7 +236,7 @@ TEST_F(StringMapTest, MoveOnlyKey) { StringMap t; t.GetOrCreateValue("Test", MoveOnly(42)); StringRef Key = "Test"; - StringMapEntry::Create(Key.begin(), Key.end(), MoveOnly(42)) + StringMapEntry::Create(Key, MoveOnly(42)) ->Destroy(); }