[llvm] r276276 - Rename StringMap::emplace_second to try_emplace.
Benjamin Kramer via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 21 06:37:48 PDT 2016
Author: d0k
Date: Thu Jul 21 08:37:48 2016
New Revision: 276276
URL: http://llvm.org/viewvc/llvm-project?rev=276276&view=rev
Log:
Rename StringMap::emplace_second to try_emplace.
Coincidentally this function maps to the C++17 try_emplace. Rename it
for consistentcy with C++17 std::map. NFC.
Modified:
llvm/trunk/include/llvm/ADT/StringMap.h
llvm/trunk/lib/IR/Metadata.cpp
llvm/trunk/lib/Transforms/Instrumentation/GCOVProfiling.cpp
llvm/trunk/unittests/ADT/StringMapTest.cpp
llvm/trunk/unittests/ProfileData/CoverageMappingTest.cpp
Modified: llvm/trunk/include/llvm/ADT/StringMap.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/StringMap.h?rev=276276&r1=276275&r2=276276&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ADT/StringMap.h (original)
+++ llvm/trunk/include/llvm/ADT/StringMap.h Thu Jul 21 08:37:48 2016
@@ -329,9 +329,7 @@ public:
/// Lookup the ValueTy for the \p Key, or create a default constructed value
/// if the key is not in the map.
- ValueTy &operator[](StringRef Key) {
- return emplace_second(Key).first->second;
- }
+ ValueTy &operator[](StringRef Key) { return try_emplace(Key).first->second; }
/// count - Return 1 if the element is in the map, 0 otherwise.
size_type count(StringRef Key) const {
@@ -362,7 +360,7 @@ public:
/// if and only if the insertion takes place, and the iterator component of
/// the pair points to the element with key equivalent to the key of the pair.
std::pair<iterator, bool> insert(std::pair<StringRef, ValueTy> KV) {
- return emplace_second(KV.first, std::move(KV.second));
+ return try_emplace(KV.first, std::move(KV.second));
}
/// Emplace a new element for the specified key into the map if the key isn't
@@ -370,7 +368,7 @@ public:
/// if and only if the insertion takes place, and the iterator component of
/// the pair points to the element with key equivalent to the key of the pair.
template <typename... ArgsTy>
- std::pair<iterator, bool> emplace_second(StringRef Key, ArgsTy &&... Args) {
+ std::pair<iterator, bool> try_emplace(StringRef Key, ArgsTy &&... Args) {
unsigned BucketNo = LookupBucketFor(Key);
StringMapEntryBase *&Bucket = TheTable[BucketNo];
if (Bucket && Bucket != getTombstoneVal())
Modified: llvm/trunk/lib/IR/Metadata.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/Metadata.cpp?rev=276276&r1=276275&r2=276276&view=diff
==============================================================================
--- llvm/trunk/lib/IR/Metadata.cpp (original)
+++ llvm/trunk/lib/IR/Metadata.cpp Thu Jul 21 08:37:48 2016
@@ -416,7 +416,7 @@ void ValueAsMetadata::handleRAUW(Value *
MDString *MDString::get(LLVMContext &Context, StringRef Str) {
auto &Store = Context.pImpl->MDStringCache;
- auto I = Store.emplace_second(Str);
+ auto I = Store.try_emplace(Str);
auto &MapEntry = I.first->getValue();
if (!I.second)
return &MapEntry;
Modified: llvm/trunk/lib/Transforms/Instrumentation/GCOVProfiling.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Instrumentation/GCOVProfiling.cpp?rev=276276&r1=276275&r2=276276&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Instrumentation/GCOVProfiling.cpp (original)
+++ llvm/trunk/lib/Transforms/Instrumentation/GCOVProfiling.cpp Thu Jul 21 08:37:48 2016
@@ -251,7 +251,7 @@ namespace {
class GCOVBlock : public GCOVRecord {
public:
GCOVLines &getFile(StringRef Filename) {
- return LinesByFile.emplace_second(Filename, Filename, os).first->second;
+ return LinesByFile.try_emplace(Filename, Filename, os).first->second;
}
void addEdge(GCOVBlock &Successor) {
Modified: llvm/trunk/unittests/ADT/StringMapTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/ADT/StringMapTest.cpp?rev=276276&r1=276275&r2=276276&view=diff
==============================================================================
--- llvm/trunk/unittests/ADT/StringMapTest.cpp (original)
+++ llvm/trunk/unittests/ADT/StringMapTest.cpp Thu Jul 21 08:37:48 2016
@@ -458,7 +458,7 @@ struct NonMoveableNonCopyableType {
// Test that we can "emplace" an element in the map without involving map/move
TEST(StringMapCustomTest, EmplaceTest) {
StringMap<NonMoveableNonCopyableType> Map;
- Map.emplace_second("abcd", 42);
+ Map.try_emplace("abcd", 42);
EXPECT_EQ(1u, Map.count("abcd"));
EXPECT_EQ(42, Map["abcd"].Data);
}
Modified: llvm/trunk/unittests/ProfileData/CoverageMappingTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/ProfileData/CoverageMappingTest.cpp?rev=276276&r1=276275&r2=276276&view=diff
==============================================================================
--- llvm/trunk/unittests/ProfileData/CoverageMappingTest.cpp (original)
+++ llvm/trunk/unittests/ProfileData/CoverageMappingTest.cpp Thu Jul 21 08:37:48 2016
@@ -116,7 +116,7 @@ struct CoverageMappingTest : ::testing::
if (R != Files.end())
return R->second;
unsigned Index = Files.size();
- Files.emplace_second(Name, Index);
+ Files.try_emplace(Name, Index);
return Index;
}
More information about the llvm-commits
mailing list