Skip to content

Commit 62213dd

Browse files
kazutakahiratatomtor
authored andcommitted
[llvm] Use *Map::try_emplace (NFC) (llvm#143321)
- try_emplace(Key) is shorter than insert(std::make_pair(Key, 0)). - try_emplace performs value initialization without value parameters. - We overwrite values on successful insertion anyway.
1 parent 77cf3f3 commit 62213dd

File tree

3 files changed

+4
-5
lines changed

3 files changed

+4
-5
lines changed

llvm/lib/Transforms/ObjCARC/BlotMapVector.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,7 @@ template <class KeyT, class ValueT> class BlotMapVector {
5353
const_iterator end() const { return Vector.end(); }
5454

5555
ValueT &operator[](const KeyT &Arg) {
56-
std::pair<typename MapTy::iterator, bool> Pair =
57-
Map.insert(std::make_pair(Arg, size_t(0)));
56+
std::pair<typename MapTy::iterator, bool> Pair = Map.try_emplace(Arg);
5857
if (Pair.second) {
5958
size_t Num = Vector.size();
6059
Pair.first->second = Num;

llvm/lib/Transforms/Scalar/ConstantHoisting.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ void ConstantHoistingPass::collectConstantCandidates(
381381
ConstCandMapType::iterator Itr;
382382
bool Inserted;
383383
ConstPtrUnionType Cand = ConstInt;
384-
std::tie(Itr, Inserted) = ConstCandMap.insert(std::make_pair(Cand, 0));
384+
std::tie(Itr, Inserted) = ConstCandMap.try_emplace(Cand);
385385
if (Inserted) {
386386
ConstIntCandVec.push_back(ConstantCandidate(ConstInt));
387387
Itr->second = ConstIntCandVec.size() - 1;
@@ -439,7 +439,7 @@ void ConstantHoistingPass::collectConstantCandidates(
439439
ConstCandMapType::iterator Itr;
440440
bool Inserted;
441441
ConstPtrUnionType Cand = ConstExpr;
442-
std::tie(Itr, Inserted) = ConstCandMap.insert(std::make_pair(Cand, 0));
442+
std::tie(Itr, Inserted) = ConstCandMap.try_emplace(Cand);
443443
if (Inserted) {
444444
ExprCandVec.push_back(ConstantCandidate(
445445
ConstantInt::get(Type::getInt32Ty(*Ctx), Offset.getLimitedValue()),

llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2788,7 +2788,7 @@ std::pair<size_t, Immediate> LSRInstance::getUse(const SCEV *&Expr,
27882788
}
27892789

27902790
std::pair<UseMapTy::iterator, bool> P =
2791-
UseMap.insert(std::make_pair(LSRUse::SCEVUseKindPair(Expr, Kind), 0));
2791+
UseMap.try_emplace(LSRUse::SCEVUseKindPair(Expr, Kind));
27922792
if (!P.second) {
27932793
// A use already existed with this base.
27942794
size_t LUIdx = P.first->second;

0 commit comments

Comments
 (0)