From c39a8b439a7dc209c658bd7ba69cc4d7fb4f634b Mon Sep 17 00:00:00 2001 From: Wilson Snyder Date: Fri, 18 Dec 2020 18:24:47 -0500 Subject: [PATCH] Internals: Use emplace instead of insert(make_pair(...)). No functional change intended. --- include/verilated.cpp | 2 +- include/verilated_cov.cpp | 6 +++--- include/verilated_heavy.h | 3 +-- include/verilated_imp.h | 8 +++----- include/verilated_sym_props.h | 8 ++++---- include/verilated_vcd_c.cpp | 4 ++-- include/verilated_vpi.cpp | 4 +--- src/V3AstNodes.cpp | 6 +++--- src/V3AstNodes.h | 2 +- src/V3Broken.cpp | 4 ++-- src/V3Combine.cpp | 2 +- src/V3Coverage.cpp | 2 +- src/V3Dead.cpp | 2 +- src/V3Delayed.cpp | 2 +- src/V3Descope.cpp | 2 +- src/V3EmitCSyms.cpp | 6 +++--- src/V3File.cpp | 6 +++--- src/V3FileLine.cpp | 2 +- src/V3Graph.cpp | 2 +- src/V3GraphDfa.cpp | 2 +- src/V3GraphStream.h | 4 ++-- src/V3Hashed.cpp | 4 ++-- src/V3HierBlock.cpp | 2 +- src/V3Inst.cpp | 2 +- src/V3LanguageWords.h | 2 +- src/V3Life.cpp | 10 +++++----- src/V3LinkDot.cpp | 12 +++++------- src/V3Options.cpp | 8 ++++---- src/V3Order.cpp | 2 +- src/V3Param.cpp | 16 ++++++++-------- src/V3PreProc.cpp | 2 +- src/V3Scope.cpp | 8 ++++---- src/V3Split.cpp | 2 +- src/V3SplitVar.cpp | 4 +--- src/V3StatsReport.cpp | 8 ++++---- src/V3SymTable.h | 2 +- src/V3Task.cpp | 2 +- src/V3Trace.cpp | 2 +- src/V3Tristate.cpp | 2 +- src/V3Width.cpp | 11 +++++------ src/VlcPoint.h | 2 +- 41 files changed, 86 insertions(+), 96 deletions(-) diff --git a/include/verilated.cpp b/include/verilated.cpp index a28bb0f98..b38855679 100644 --- a/include/verilated.cpp +++ b/include/verilated.cpp @@ -2740,7 +2740,7 @@ void VerilatedScope::varInsert(int finalize, const char* namep, void* datap, boo } va_end(ap); - m_varsp->insert(std::make_pair(namep, var)); + m_varsp->emplace(namep, var); } // cppcheck-suppress unusedFunction // Used by applications diff --git a/include/verilated_cov.cpp b/include/verilated_cov.cpp index 45f111cd9..dbfbebb3f 100644 --- a/include/verilated_cov.cpp +++ b/include/verilated_cov.cpp @@ -123,8 +123,8 @@ private: if (iter != m_valueIndexes.end()) return iter->second; m_nextIndex++; assert(m_nextIndex > 0); // Didn't rollover - m_valueIndexes.insert(std::make_pair(value, m_nextIndex)); - m_indexValues.insert(std::make_pair(m_nextIndex, value)); + m_valueIndexes.emplace(value, m_nextIndex); + m_indexValues.emplace(m_nextIndex, value); return m_nextIndex; } static std::string dequote(const std::string& text) VL_PURE { @@ -390,7 +390,7 @@ public: cit->second.second += itemp->count(); cit->second.first = combineHier(oldhier, hier); } else { - eventCounts.insert(std::make_pair(name, make_pair(hier, itemp->count()))); + eventCounts.emplace(name, make_pair(hier, itemp->count())); } } diff --git a/include/verilated_heavy.h b/include/verilated_heavy.h index f284241ea..bb6e993e5 100644 --- a/include/verilated_heavy.h +++ b/include/verilated_heavy.h @@ -566,8 +566,7 @@ public: T_Value& at(const T_Key& index) { const auto it = m_map.find(index); if (it == m_map.end()) { - std::pair pit - = m_map.insert(std::make_pair(index, m_defaultValue)); + std::pair pit = m_map.emplace(index, m_defaultValue); return pit.first->second; } return it->second; diff --git a/include/verilated_imp.h b/include/verilated_imp.h index b468f4ead..2a54a221c 100644 --- a/include/verilated_imp.h +++ b/include/verilated_imp.h @@ -331,7 +331,7 @@ public: if (it != s_s.v.m_userMap.end()) { it->second = userData; } else { - s_s.v.m_userMap.insert(it, std::make_pair(std::make_pair(scopep, userKey), userData)); + s_s.v.m_userMap.emplace(std::make_pair(scopep, userKey), userData); } } static inline void* userFind(const void* scopep, void* userKey) VL_MT_SAFE { @@ -374,9 +374,7 @@ public: // But only for verilated*.cpp // Slow ok - called once/scope at construction const VerilatedLockGuard lock(s_s.v.m_nameMutex); const auto it = s_s.v.m_nameMap.find(scopep->name()); - if (it == s_s.v.m_nameMap.end()) { - s_s.v.m_nameMap.insert(it, std::make_pair(scopep->name(), scopep)); - } + if (it == s_s.v.m_nameMap.end()) s_s.v.m_nameMap.emplace(scopep->name(), scopep); } static inline const VerilatedScope* scopeFind(const char* namep) VL_MT_SAFE { const VerilatedLockGuard lock(s_s.v.m_nameMutex); @@ -442,7 +440,7 @@ public: // But only for verilated*.cpp const VerilatedLockGuard lock(s_s.v.m_exportMutex); const auto it = s_s.v.m_exportMap.find(namep); if (it == s_s.v.m_exportMap.end()) { - s_s.v.m_exportMap.insert(it, std::make_pair(namep, s_s.v.m_exportNext++)); + s_s.v.m_exportMap.emplace(namep, s_s.v.m_exportNext++); return s_s.v.m_exportNext++; } else { return it->second; diff --git a/include/verilated_sym_props.h b/include/verilated_sym_props.h index 9a49cfc6e..5cbe877aa 100644 --- a/include/verilated_sym_props.h +++ b/include/verilated_sym_props.h @@ -44,15 +44,15 @@ protected: friend class VerilatedVarProps; friend class VerilatedScope; VerilatedRange() = default; - VerilatedRange(int left, int right) - : m_left{left} - , m_right{right} {} void init(int left, int right) { m_left = left; m_right = right; } public: + VerilatedRange(int left, int right) + : m_left{left} + , m_right{right} {} ~VerilatedRange() = default; int left() const { return m_left; } int right() const { return m_right; } @@ -83,7 +83,7 @@ class VerilatedVarProps VL_NOT_FINAL { for (int i = 0; i < m_udims; ++i) { const int left = ulims ? ulims[2 * i + 0] : 0; const int right = ulims ? ulims[2 * i + 1] : 0; - m_unpacked.push_back(VerilatedRange(left, right)); + m_unpacked.emplace_back(left, right); } } // CONSTRUCTORS diff --git a/include/verilated_vcd_c.cpp b/include/verilated_vcd_c.cpp index 9339eced7..9d7d21640 100644 --- a/include/verilated_vcd_c.cpp +++ b/include/verilated_vcd_c.cpp @@ -198,7 +198,7 @@ void VerilatedVcd::makeNameMap() { std::string newname = std::string("top"); if (hiername[0] != '\t') newname += ' '; newname += hiername; - newmapp->insert(std::make_pair(newname, decl)); + newmapp->emplace(newname, decl); } deleteNameMap(); m_namemapp = newmapp; @@ -511,7 +511,7 @@ void VerilatedVcd::declare(vluint32_t code, const char* name, const char* wirep, decl += buf; } decl += " $end\n"; - m_namemapp->insert(std::make_pair(hiername, decl)); + m_namemapp->emplace(hiername, decl); } void VerilatedVcd::declBit(vluint32_t code, const char* name, bool array, int arraynum) { diff --git a/include/verilated_vpi.cpp b/include/verilated_vpi.cpp index 8693bca46..a9ac7d68d 100644 --- a/include/verilated_vpi.cpp +++ b/include/verilated_vpi.cpp @@ -461,9 +461,7 @@ public: } s_s.m_cbObjLists[vop->reason()].push_back(vop); } - static void cbTimedAdd(VerilatedVpioCb* vop) { - s_s.m_timedCbs.insert(std::make_pair(vop->time(), vop)); - } + static void cbTimedAdd(VerilatedVpioCb* vop) { s_s.m_timedCbs.emplace(vop->time(), vop); } static void cbReasonRemove(VerilatedVpioCb* cbp) { VpioCbList& cbObjList = s_s.m_cbObjLists[cbp->reason()]; // We do not remove it now as we may be iterating the list, diff --git a/src/V3AstNodes.cpp b/src/V3AstNodes.cpp index 0215fb47b..dbd2a8716 100644 --- a/src/V3AstNodes.cpp +++ b/src/V3AstNodes.cpp @@ -68,7 +68,7 @@ void AstNodeUOrStructDType::repairMemberCache() { if (m_members.find(itemp->name()) != m_members.end()) { itemp->v3error("Duplicate declaration of member name: " << itemp->prettyNameQ()); } else { - m_members.insert(make_pair(itemp->name(), itemp)); + m_members.emplace(itemp->name(), itemp); } } } @@ -995,7 +995,7 @@ AstBasicDType* AstTypeTable::findInsertSameDType(AstBasicDType* nodep) { DetailedMap& mapr = m_detailedMap; const auto it = mapr.find(key); if (it != mapr.end()) return it->second; - mapr.insert(make_pair(key, nodep)); + mapr.emplace(key, nodep); nodep->generic(true); // No addTypesp; the upper function that called new() is responsible for adding return nodep; @@ -1168,7 +1168,7 @@ void AstClass::insertCache(AstNode* nodep) { if (m_members.find(nodep->name()) != m_members.end()) { nodep->v3error("Duplicate declaration of member name: " << nodep->prettyNameQ()); } else { - m_members.insert(make_pair(nodep->name(), nodep)); + m_members.emplace(nodep->name(), nodep); } } } diff --git a/src/V3AstNodes.h b/src/V3AstNodes.h index 1676a21d4..20c418bd7 100644 --- a/src/V3AstNodes.h +++ b/src/V3AstNodes.h @@ -5020,7 +5020,7 @@ public: it->second->valuep(newp); } else { AstInitItem* itemp = new AstInitItem(fileline(), newp); - m_map.insert(it, make_pair(index, itemp)); + m_map.emplace(index, itemp); addOp2p(itemp); } return oldp; diff --git a/src/V3Broken.cpp b/src/V3Broken.cpp index 5fa7df17a..739c823a4 100644 --- a/src/V3Broken.cpp +++ b/src/V3Broken.cpp @@ -73,7 +73,7 @@ public: "Newing AstNode object that is already allocated"); if (iter == s_nodes.end()) { int flags = FLAG_ALLOCATED; // This int needed to appease GCC 4.1.2 - s_nodes.insert(make_pair(nodep, flags)); + s_nodes.emplace(nodep, flags); } } static void setUnder(const AstNode* nodep, bool flag) { @@ -105,7 +105,7 @@ public: } int or_flags = FLAG_IN_TREE | (linkable ? FLAG_LINKABLE : 0); if (iter == s_nodes.end()) { - s_nodes.insert(make_pair(nodep, or_flags)); + s_nodes.emplace(nodep, or_flags); } else { iter->second |= or_flags; } diff --git a/src/V3Combine.cpp b/src/V3Combine.cpp index 64c9055eb..6659b2f54 100644 --- a/src/V3Combine.cpp +++ b/src/V3Combine.cpp @@ -106,7 +106,7 @@ public: } } // METHODS - void addCall(AstCCall* nodep) { m_callMmap.insert(make_pair(nodep->funcp(), nodep)); } + void addCall(AstCCall* nodep) { m_callMmap.emplace(nodep->funcp(), nodep); } void deleteCall(AstCCall* nodep) { std::pair eqrange = m_callMmap.equal_range(nodep->funcp()); diff --git a/src/V3Coverage.cpp b/src/V3Coverage.cpp index d7699cc66..1b0cbd0f1 100644 --- a/src/V3Coverage.cpp +++ b/src/V3Coverage.cpp @@ -142,7 +142,7 @@ private: + cvtToStr(nodep->fileline()->lineno()) + "_" + type; const auto it = m_varnames.find(name); if (it == m_varnames.end()) { - m_varnames.insert(make_pair(name, 1)); + m_varnames.emplace(name, 1); } else { int suffix = (it->second)++; name += "_" + cvtToStr(suffix); diff --git a/src/V3Dead.cpp b/src/V3Dead.cpp index 3e8790c90..80c49f0b0 100644 --- a/src/V3Dead.cpp +++ b/src/V3Dead.cpp @@ -285,7 +285,7 @@ private: AstVarRef* varrefp = VN_CAST(nodep->lhsp(), VarRef); if (varrefp && !m_sideEffect && varrefp->varScopep()) { // For simplicity, we only remove post-scoping - m_assignMap.insert(make_pair(varrefp->varScopep(), nodep)); + m_assignMap.emplace(varrefp->varScopep(), nodep); checkAll(varrefp); // Must track reference to dtype() checkVarRef(varrefp); } else { // Track like any other statement diff --git a/src/V3Delayed.cpp b/src/V3Delayed.cpp index d5005bf46..099ae391a 100644 --- a/src/V3Delayed.cpp +++ b/src/V3Delayed.cpp @@ -150,7 +150,7 @@ private: VFlagBitPacked(), width); } addmodp->addStmtp(varp); - m_modVarMap.insert(make_pair(make_pair(addmodp, name), varp)); + m_modVarMap.emplace(make_pair(addmodp, name), varp); } AstVarScope* varscp = new AstVarScope(oldvarscp->fileline(), oldvarscp->scopep(), varp); diff --git a/src/V3Descope.cpp b/src/V3Descope.cpp index cb181eb09..9d2f87f75 100644 --- a/src/V3Descope.cpp +++ b/src/V3Descope.cpp @@ -296,7 +296,7 @@ private: if (nodep->funcPublic()) { // There may be multiple public functions by the same name; // record for later correction or making of shells - m_modFuncs.insert(make_pair(nodep->name(), nodep)); + m_modFuncs.emplace(nodep->name(), nodep); nodep->name(m_scopep->nameDotless() + "__" + nodep->name()); } } diff --git a/src/V3EmitCSyms.cpp b/src/V3EmitCSyms.cpp index ac049309a..488016f61 100644 --- a/src/V3EmitCSyms.cpp +++ b/src/V3EmitCSyms.cpp @@ -172,7 +172,7 @@ class EmitCSyms final : EmitCBaseVisitor { const auto scpit = m_vpiScopeCandidates.find(scp); if ((scpit != m_vpiScopeCandidates.end()) && (m_scopeNames.find(scp) == m_scopeNames.end())) { - m_scopeNames.insert(make_pair(scpit->second.m_symName, scpit->second)); + m_scopeNames.emplace(scpit->second.m_symName, scpit->second); } string::size_type pos = scp.rfind("__DOT__"); if (pos == string::npos) { @@ -313,8 +313,8 @@ class EmitCSyms final : EmitCBaseVisitor { // <<" ss"<timeunit().powerOfTen() : 0; if (m_scopeNames.find(name) == m_scopeNames.end()) { - m_scopeNames.insert(make_pair( - name, ScopeData(name, nodep->scopePrettySymName(), timeunit, "SCOPE_OTHER"))); + m_scopeNames.emplace( + name, ScopeData(name, nodep->scopePrettySymName(), timeunit, "SCOPE_OTHER")); } if (nodep->dpiExport()) { UASSERT_OBJ(m_cfuncp, nodep, "ScopeName not under DPI function"); diff --git a/src/V3File.cpp b/src/V3File.cpp index 66f82abbb..53d446d05 100644 --- a/src/V3File.cpp +++ b/src/V3File.cpp @@ -580,7 +580,7 @@ protected: // Cache small files (only to save space) // It's quite common to `include "timescale" thousands of times // This isn't so important if it's just an open(), but filtering can be slow - m_contentsMap.insert(make_pair(filename, listString(outl))); + m_contentsMap.emplace(filename, listString(outl)); } return true; } @@ -980,7 +980,7 @@ public: UASSERT(old == it->second, "Passthru request for '" + old + "' after already --protect-ids of it."); } else { - m_nameMap.insert(make_pair(old, old)); + m_nameMap.emplace(old, old); m_newIdSet.insert(old); } return old; @@ -1011,7 +1011,7 @@ public: } } } - m_nameMap.insert(make_pair(old, out)); + m_nameMap.emplace(old, out); m_newIdSet.insert(out); return out; } diff --git a/src/V3FileLine.cpp b/src/V3FileLine.cpp index a68d2348d..de4ac2ca7 100644 --- a/src/V3FileLine.cpp +++ b/src/V3FileLine.cpp @@ -63,7 +63,7 @@ int FileLineSingleton::nameToNumber(const string& filename) { int num = m_names.size(); m_names.push_back(filename); m_languages.push_back(V3LangCode::mostRecent()); - m_namemap.insert(make_pair(filename, num)); + m_namemap.emplace(filename, num); return num; } diff --git a/src/V3Graph.cpp b/src/V3Graph.cpp index 518c1ce70..aac916a72 100644 --- a/src/V3Graph.cpp +++ b/src/V3Graph.cpp @@ -330,7 +330,7 @@ void V3Graph::dumpDotFile(const string& filename, bool colorAsSubgraph) const { for (V3GraphVertex* vertexp = verticesBeginp(); vertexp; vertexp = vertexp->verticesNextp()) { string vertexSubgraph = (colorAsSubgraph && vertexp->color()) ? cvtToStr(vertexp->color()) : ""; - subgraphs.insert(make_pair(vertexSubgraph, vertexp)); + subgraphs.emplace(vertexSubgraph, vertexp); } // We use a map here, as we don't want to corrupt anything (userp) in the graph, diff --git a/src/V3GraphDfa.cpp b/src/V3GraphDfa.cpp index 3d193aca3..93de48083 100644 --- a/src/V3GraphDfa.cpp +++ b/src/V3GraphDfa.cpp @@ -167,7 +167,7 @@ private: void insertDfaOrigins(DfaVertex* dfaStatep) { // Record the NFA states this dfa came from uint32_t hash = hashDfaOrigins(dfaStatep); - m_hashMap.insert(make_pair(hash, dfaStatep)); + m_hashMap.emplace(hash, dfaStatep); } DfaVertex* findDfaOrigins(const DfaStates& nfasWithInput) { diff --git a/src/V3GraphStream.h b/src/V3GraphStream.h index f7bd78cb5..4ff711145 100644 --- a/src/V3GraphStream.h +++ b/src/V3GraphStream.h @@ -115,7 +115,7 @@ public: depCount++; } VxHolder newVx(vxp, pos++, depCount); - m_waitingVertices.insert(make_pair(vxp, newVx)); + m_waitingVertices.emplace(vxp, newVx); } } else { // REVERSE if (vxp->outEmpty()) { @@ -127,7 +127,7 @@ public: depCount++; } VxHolder newVx(vxp, pos++, depCount); - m_waitingVertices.insert(make_pair(vxp, newVx)); + m_waitingVertices.emplace(vxp, newVx); } } } diff --git a/src/V3Hashed.cpp b/src/V3Hashed.cpp index a72e45106..754f623d6 100644 --- a/src/V3Hashed.cpp +++ b/src/V3Hashed.cpp @@ -115,7 +115,7 @@ V3Hash V3Hashed::uncachedHash(const AstNode* nodep) { V3Hashed::iterator V3Hashed::hashAndInsert(AstNode* nodep) { hash(nodep); - return m_hashMmap.insert(make_pair(nodeHash(nodep), nodep)); + return m_hashMmap.emplace(nodeHash(nodep), nodep); } void V3Hashed::hash(AstNode* nodep) { @@ -162,7 +162,7 @@ void V3Hashed::dumpFile(const string& filename, bool tree) { if (it != end()) lasthash = it->first; if (num_in_bucket) { if (dist.find(num_in_bucket) == dist.end()) { - dist.insert(make_pair(num_in_bucket, 1)); + dist.emplace(num_in_bucket, 1); } else { ++dist[num_in_bucket]; } diff --git a/src/V3HierBlock.cpp b/src/V3HierBlock.cpp index 41f647826..c18554c12 100644 --- a/src/V3HierBlock.cpp +++ b/src/V3HierBlock.cpp @@ -314,7 +314,7 @@ void V3HierBlockPlan::add(const AstNodeModule* modp, const std::vector& V3HierBlock* hblockp = new V3HierBlock(modp, gparams); UINFO(3, "Add " << modp->prettyNameQ() << " with " << gparams.size() << " parameters" << std::endl); - m_blocks.insert(std::make_pair(modp, hblockp)); + m_blocks.emplace(modp, hblockp); } } diff --git a/src/V3Inst.cpp b/src/V3Inst.cpp index 624d29bce..699b860dc 100644 --- a/src/V3Inst.cpp +++ b/src/V3Inst.cpp @@ -161,7 +161,7 @@ public: // METHODS void insert(AstVar* nodep) { UINFO(8, " dmINSERT " << nodep << endl); - m_modVarNameMap.insert(make_pair(nodep->name(), nodep)); + m_modVarNameMap.emplace(nodep->name(), nodep); } AstVar* find(const string& name) { const auto it = m_modVarNameMap.find(name); diff --git a/src/V3LanguageWords.h b/src/V3LanguageWords.h index 37cc5bee9..37de2e867 100644 --- a/src/V3LanguageWords.h +++ b/src/V3LanguageWords.h @@ -31,7 +31,7 @@ private: struct Singleton { KeywordMap s_kwdMap; // List of keywords, and what language applies Singleton() { init(); } - void addKwd(const string& kwd, const string& why) { s_kwdMap.insert(make_pair(kwd, why)); } + void addKwd(const string& kwd, const string& why) { s_kwdMap.emplace(kwd, why); } void init(); }; diff --git a/src/V3Life.cpp b/src/V3Life.cpp index daa9028f5..61e03ea1b 100644 --- a/src/V3Life.cpp +++ b/src/V3Life.cpp @@ -165,7 +165,7 @@ public: checkRemoveAssign(it); it->second.simpleAssign(assp); } else { - m_map.insert(make_pair(nodep, LifeVarEntry(LifeVarEntry::SIMPLEASSIGN(), assp))); + m_map.emplace(nodep, LifeVarEntry(LifeVarEntry::SIMPLEASSIGN(), assp)); } // lifeDump(); } @@ -175,7 +175,7 @@ public: if (it != m_map.end()) { it->second.complexAssign(); } else { - m_map.insert(make_pair(nodep, LifeVarEntry(LifeVarEntry::COMPLEXASSIGN()))); + m_map.emplace(nodep, LifeVarEntry(LifeVarEntry::COMPLEXASSIGN())); } } void varUsageReplace(AstVarScope* nodep, AstVarRef* varrefp) { @@ -196,7 +196,7 @@ public: UINFO(4, " usage: " << nodep << endl); it->second.consumed(); } else { - m_map.insert(make_pair(nodep, LifeVarEntry(LifeVarEntry::CONSUMED()))); + m_map.emplace(nodep, LifeVarEntry(LifeVarEntry::CONSUMED())); } } void complexAssignFind(AstVarScope* nodep) { @@ -205,7 +205,7 @@ public: UINFO(4, " casfind: " << it->first << endl); it->second.complexAssign(); } else { - m_map.insert(make_pair(nodep, LifeVarEntry(LifeVarEntry::COMPLEXASSIGN()))); + m_map.emplace(nodep, LifeVarEntry(LifeVarEntry::COMPLEXASSIGN())); } } void consumedFind(AstVarScope* nodep) { @@ -213,7 +213,7 @@ public: if (it != m_map.end()) { it->second.consumed(); } else { - m_map.insert(make_pair(nodep, LifeVarEntry(LifeVarEntry::CONSUMED()))); + m_map.emplace(nodep, LifeVarEntry(LifeVarEntry::CONSUMED())); } } void lifeToAbove() { diff --git a/src/V3LinkDot.cpp b/src/V3LinkDot.cpp index 2c3556996..a8b6616ff 100644 --- a/src/V3LinkDot.cpp +++ b/src/V3LinkDot.cpp @@ -304,7 +304,7 @@ public: nodep->user1p(symp); checkDuplicate(rootEntp(), nodep, nodep->origName()); rootEntp()->insert(nodep->origName(), symp); - if (forScopeCreation()) m_nameScopeSymMap.insert(make_pair(scopename, symp)); + if (forScopeCreation()) m_nameScopeSymMap.emplace(scopename, symp); return symp; } VSymEnt* insertCell(VSymEnt* abovep, VSymEnt* modSymp, AstCell* nodep, @@ -326,11 +326,11 @@ public: // have 2 same cells under an if modSymp->reinsert(nodep->name(), symp); } - if (forScopeCreation()) m_nameScopeSymMap.insert(make_pair(scopename, symp)); + if (forScopeCreation()) m_nameScopeSymMap.emplace(scopename, symp); return symp; } void insertMap(VSymEnt* symp, const string& scopename) { - if (forScopeCreation()) m_nameScopeSymMap.insert(make_pair(scopename, symp)); + if (forScopeCreation()) m_nameScopeSymMap.emplace(scopename, symp); } VSymEnt* insertInline(VSymEnt* abovep, VSymEnt* modSymp, AstCellInline* nodep, @@ -409,9 +409,7 @@ public: // Mark the given variable name as being allowed to be implicitly declared if (nodep) { const auto it = m_implicitNameSet.find(make_pair(nodep, varname)); - if (it == m_implicitNameSet.end()) { - m_implicitNameSet.insert(make_pair(nodep, varname)); - } + if (it == m_implicitNameSet.end()) { m_implicitNameSet.emplace(nodep, varname); } } } bool implicitOk(AstNodeModule* nodep, const string& varname) { @@ -501,7 +499,7 @@ public: UASSERT_OBJ( !(VN_IS(rhsp->nodep(), Cell) && !VN_IS(VN_CAST(rhsp->nodep(), Cell)->modp(), Iface)), rhsp->nodep(), "Got a non-IFACE alias RHS"); - m_scopeAliasMap[samn].insert(make_pair(lhsp, rhsp)); + m_scopeAliasMap[samn].emplace(lhsp, rhsp); } void computeScopeAliases() { UINFO(9, "computeIfaceAliases\n"); diff --git a/src/V3Options.cpp b/src/V3Options.cpp index 42903f6e2..68a4a8df9 100644 --- a/src/V3Options.cpp +++ b/src/V3Options.cpp @@ -458,7 +458,7 @@ string V3Options::fileExists(const string& filename) { auto diriter = m_impp->m_dirMap.find(dir); if (diriter == m_impp->m_dirMap.end()) { // Read the listing - m_impp->m_dirMap.insert(std::make_pair(dir, std::set())); + m_impp->m_dirMap.emplace(dir, std::set()); diriter = m_impp->m_dirMap.find(dir); std::set* setp = &(diriter->second); @@ -1229,7 +1229,7 @@ void V3Options::parseOptsList(FileLine* fl, const string& optdir, int argc, char } else if (!strcmp(sw, "-hierarchical-block") && (i + 1) < argc) { shift; V3HierarchicalBlockOption opt(argv[i]); - m_hierBlocks.insert(std::make_pair(opt.mangledName(), opt)); + m_hierBlocks.emplace(opt.mangledName(), opt); } else if (!strncmp(sw, "-I", 2)) { addIncDirUser(parseFileArg(optdir, string(sw + strlen("-I")))); } else if (!strcmp(sw, "-if-depth") && (i + 1) < argc) { @@ -1814,7 +1814,7 @@ void V3Options::setDebugSrcLevel(const string& srcfile, int level) { if (iter != m_debugSrcs.end()) { iter->second = level; } else { - m_debugSrcs.insert(make_pair(srcfile, level)); + m_debugSrcs.emplace(srcfile, level); } } @@ -1835,7 +1835,7 @@ void V3Options::setDumpTreeLevel(const string& srcfile, int level) { if (iter != m_dumpTrees.end()) { iter->second = level; } else { - m_dumpTrees.insert(make_pair(srcfile, level)); + m_dumpTrees.emplace(srcfile, level); } } diff --git a/src/V3Order.cpp b/src/V3Order.cpp index faa50f0da..0b1b05f3d 100644 --- a/src/V3Order.cpp +++ b/src/V3Order.cpp @@ -164,7 +164,7 @@ public: return iter->second; } else { OrderMoveDomScope* domScopep = new OrderMoveDomScope(domainp, scopep); - s_dsMap.insert(make_pair(key, domScopep)); + s_dsMap.emplace(key, domScopep); return domScopep; } } diff --git a/src/V3Param.cpp b/src/V3Param.cpp index 68aa28d5e..00fad3e4d 100644 --- a/src/V3Param.cpp +++ b/src/V3Param.cpp @@ -137,7 +137,7 @@ public: for (AstNodeModule* modp = nodep->modulesp(); modp; modp = VN_CAST(modp->nextp(), NodeModule)) { if (hierOpts.find(modp->prettyName()) != hierOpts.end()) { - m_hierBlockMod.insert(std::make_pair(modp->name(), modp)); + m_hierBlockMod.emplace(modp->name(), modp); } } } @@ -321,7 +321,7 @@ class ParamProcessor final { // We use all upper case above, so lower here can't conflict newname += "__pi" + cvtToStr(++m_longId); } - m_longMap.insert(make_pair(longname, newname)); + m_longMap.emplace(longname, newname); } } UINFO(4, "Name: " << srcModp->name() << "->" << longname << "->" << newname << endl); @@ -349,12 +349,12 @@ class ParamProcessor final { AstVar* oldvarp = varp->clonep(); // UINFO(8,"Clone list 0x"< 0x"<<(uint32_t)varp<insert(make_pair(oldvarp, varp)); + clonemapp->emplace(oldvarp, varp); } } else if (AstParamTypeDType* ptp = VN_CAST(stmtp, ParamTypeDType)) { if (ptp->isGParam()) { AstParamTypeDType* oldptp = ptp->clonep(); - clonemapp->insert(make_pair(oldptp, ptp)); + clonemapp->emplace(oldptp, ptp); } } } @@ -383,7 +383,7 @@ class ParamProcessor final { for (AstNode* stmtp = modp->stmtsp(); stmtp; stmtp = stmtp->nextp()) { if (AstVar* varp = VN_CAST(stmtp, Var)) { if (varp->isIO() || varp->isGParam() || varp->isIfaceRef()) { - nameToPin.insert(make_pair(varp->name(), varp)); + nameToPin.emplace(varp->name(), varp); } } } @@ -474,7 +474,7 @@ class ParamProcessor final { } insertp->addNextHere(newmodp); - m_modNameMap.insert(make_pair(newmodp->name(), ModInfo(newmodp))); + m_modNameMap.emplace(newmodp->name(), ModInfo(newmodp)); auto iter = m_modNameMap.find(newname); CloneMap* clonemapp = &(iter->second.m_cloneMap); UINFO(4, " De-parameterize to new: " << newmodp << endl); @@ -758,7 +758,7 @@ class ParamVisitor final : public AstNVisitor { UASSERT_OBJ(nodep->modp(), nodep, "Not linked?"); m_processor.cellDeparam(nodep, m_modp, hierName); // Remember to process the child module at the end of the module - m_todoModps.insert(make_pair(nodep->modp()->level(), nodep->modp())); + m_todoModps.emplace(nodep->modp()->level(), nodep->modp()); } void visitModules() { // Loop on all modules left to process @@ -827,7 +827,7 @@ class ParamVisitor final : public AstNVisitor { || VN_IS(nodep, Class) // Nor moved classes || VN_IS(nodep, Package)) { // Likewise haven't done wrapTopPackages yet // Add request to END of modules left to process - m_todoModps.insert(make_pair(nodep->level(), nodep)); + m_todoModps.emplace(nodep->level(), nodep); m_generateHierName = ""; visitModules(); } else if (nodep->user5()) { diff --git a/src/V3PreProc.cpp b/src/V3PreProc.cpp index 122385e8f..b18dd84c8 100644 --- a/src/V3PreProc.cpp +++ b/src/V3PreProc.cpp @@ -344,7 +344,7 @@ void V3PreProcImp::define(FileLine* fl, const string& name, const string& value, } undef(name); } - m_defines.insert(make_pair(name, VDefine(fl, value, params, cmdline))); + m_defines.emplace(name, VDefine(fl, value, params, cmdline)); } } diff --git a/src/V3Scope.cpp b/src/V3Scope.cpp index cc11bdb40..3065cb4c7 100644 --- a/src/V3Scope.cpp +++ b/src/V3Scope.cpp @@ -109,7 +109,7 @@ private: (m_aboveCellp ? static_cast(m_aboveCellp) : static_cast(nodep)) ->fileline(), nodep, scopename, m_aboveScopep, m_aboveCellp); - if (VN_IS(nodep, Package)) m_packageScopes.insert(make_pair(nodep, m_scopep)); + if (VN_IS(nodep, Package)) m_packageScopes.emplace(nodep, m_scopep); // Now for each child cell, iterate the module this cell points to for (AstNode* cellnextp = nodep->stmtsp(); cellnextp; cellnextp = cellnextp->nextp()) { @@ -169,7 +169,7 @@ private: : static_cast(nodep)); m_scopep = new AstScope(abovep->fileline(), m_modp, scopename, m_aboveScopep, m_aboveCellp); - m_packageScopes.insert(make_pair(nodep, m_scopep)); + m_packageScopes.emplace(nodep, m_scopep); // Create scope for the current usage of this cell AstNode::user1ClearTree(); @@ -272,7 +272,7 @@ private: nodep->attrClocker(VVarAttrClocker::CLOCKER_NO); } UASSERT_OBJ(m_scopep, nodep, "No scope for var"); - m_varScopes.insert(make_pair(make_pair(nodep, m_scopep), varscp)); + m_varScopes.emplace(make_pair(nodep, m_scopep), varscp); m_scopep->addVarp(varscp); } } @@ -287,7 +287,7 @@ private: // the var's referenced package etc might not be created yet. // So push to a list and post-correct. // No check here for nodep->classOrPackagep(), will check when walk list. - m_varRefScopes.insert(make_pair(nodep, m_scopep)); + m_varRefScopes.emplace(nodep, m_scopep); } } virtual void visit(AstScopeName* nodep) override { diff --git a/src/V3Split.cpp b/src/V3Split.cpp index 9b7e0cd85..850a481f4 100644 --- a/src/V3Split.cpp +++ b/src/V3Split.cpp @@ -528,7 +528,7 @@ protected: int currOrder = 0; // Existing sequence number of assignment for (AstNode* nextp = nodep; nextp; nextp = nextp->nextp()) { SplitLogicVertex* vvertexp = reinterpret_cast(nextp->user3p()); - rankMap.insert(make_pair(vvertexp->rank(), nextp)); + rankMap.emplace(vvertexp->rank(), nextp); nextp->user4(++currOrder); // Record current ordering } diff --git a/src/V3SplitVar.cpp b/src/V3SplitVar.cpp index ac88d2def..dc07ad569 100644 --- a/src/V3SplitVar.cpp +++ b/src/V3SplitVar.cpp @@ -873,9 +873,7 @@ class PackedVarRef final { // Use raw pointer to dedup typedef std::map NodeIndices; NodeIndices nodes; - for (size_t i = 0; i < refs.size(); ++i) { - nodes.insert(std::make_pair(refs[i].nodep(), i)); - } + for (size_t i = 0; i < refs.size(); ++i) { nodes.emplace(refs[i].nodep(), i); } std::vector vect; vect.reserve(nodes.size()); for (NodeIndices::const_iterator it = nodes.begin(), it_end = nodes.end(); it != it_end; diff --git a/src/V3StatsReport.cpp b/src/V3StatsReport.cpp index 24c84932e..af021d9ce 100644 --- a/src/V3StatsReport.cpp +++ b/src/V3StatsReport.cpp @@ -54,7 +54,7 @@ class StatsReport final { // * is always first for (auto& itr : s_allStats) { V3Statistic* repp = &itr; - byName.insert(make_pair(repp->name(), repp)); + byName.emplace(repp->name(), repp); } // Process duplicates @@ -79,7 +79,7 @@ class StatsReport final { const V3Statistic* repp = &itr; if (repp->stage() == "*" && repp->printit()) { if (maxWidth < repp->name().length()) maxWidth = repp->name().length(); - byName.insert(make_pair(repp->name(), repp)); + byName.emplace(repp->name(), repp); } } @@ -123,10 +123,10 @@ class StatsReport final { if (repp->stage() != "*" && repp->printit()) { if (maxWidth < repp->name().length()) maxWidth = repp->name().length(); if (stageInt.find(repp->stage()) == stageInt.end()) { - stageInt.insert(make_pair(repp->stage(), stage++)); + stageInt.emplace(repp->stage(), stage++); stages.push_back(repp->stage()); } - byName.insert(make_pair(repp->name(), repp)); + byName.emplace(repp->name(), repp); } } diff --git a/src/V3SymTable.h b/src/V3SymTable.h index c65db3ce2..0ff5111e0 100644 --- a/src/V3SymTable.h +++ b/src/V3SymTable.h @@ -129,7 +129,7 @@ public: entp->nodep()->v3fatalSrc("Inserting two symbols with same name: " << name); } } else { - m_idNameMap.insert(make_pair(name, entp)); + m_idNameMap.emplace(name, entp); } } void reinsert(const string& name, VSymEnt* entp) { diff --git a/src/V3Task.cpp b/src/V3Task.cpp index aa261231f..eca0d2f7a 100644 --- a/src/V3Task.cpp +++ b/src/V3Task.cpp @@ -912,7 +912,7 @@ private: // as it's legal for the user to attach multiple tasks to one dpi cname const auto iter = m_dpiNames.find(nodep->cname()); if (iter == m_dpiNames.end()) { - m_dpiNames.insert(make_pair(nodep->cname(), make_pair(nodep, dpiproto))); + m_dpiNames.emplace(nodep->cname(), make_pair(nodep, dpiproto)); return false; } else if (iter->second.second != dpiproto) { nodep->v3error( diff --git a/src/V3Trace.cpp b/src/V3Trace.cpp index 43c392c68..33b37a568 100644 --- a/src/V3Trace.cpp +++ b/src/V3Trace.cpp @@ -363,7 +363,7 @@ private: // make slow routines set all activity flags. actSet.erase(TraceActivityVertex::ACTIVITY_SLOW); } - traces.insert(make_pair(actSet, vtxp)); + traces.emplace(actSet, vtxp); } } } diff --git a/src/V3Tristate.cpp b/src/V3Tristate.cpp index cc192edd4..b6ddbbcbd 100644 --- a/src/V3Tristate.cpp +++ b/src/V3Tristate.cpp @@ -427,7 +427,7 @@ class TristateVisitor final : public TristateBaseVisitor { if (it == m_lhsmap.end()) { // Not found RefVec* refsp = new RefVec(); refsp->push_back(nodep); - m_lhsmap.insert(make_pair(key, refsp)); + m_lhsmap.emplace(key, refsp); } else { it->second->push_back(nodep); } diff --git a/src/V3Width.cpp b/src/V3Width.cpp index 65f4852b3..e15ef5187 100644 --- a/src/V3Width.cpp +++ b/src/V3Width.cpp @@ -2060,7 +2060,7 @@ private: << otherp->warnOther() << "... Location of original declaration\n" << otherp->warnContextSecondary()); } else { - inits.insert(make_pair(num, itemp)); + inits.emplace(num, itemp); } num.opAdd(one, constp->num()); } @@ -3371,8 +3371,7 @@ private: patp = nullptr; break; } else { - std::pair ret - = patmap.insert(make_pair(memp, patp)); + std::pair ret = patmap.emplace(memp, patp); if (!ret.second) { patp->v3error("Assignment pattern contains duplicate entry: " << VN_CAST(patp->keyp(), Text)->text()); @@ -5836,7 +5835,7 @@ private: initp->addValuep(dimensionValue(nodep->fileline(), nodep, attrType, i)); } userIterate(varp, nullptr); // May have already done $unit so must do this var - m_tableMap.insert(make_pair(make_pair(nodep, attrType), varp)); + m_tableMap.emplace(make_pair(nodep, attrType), varp); return varp; } uint64_t enumMaxValue(const AstNode* errNodep, const AstEnumDType* adtypep) { @@ -5936,7 +5935,7 @@ private: if (values[i]) initp->addIndexValuep(i, values[i]); } userIterate(varp, nullptr); // May have already done $unit so must do this var - m_tableMap.insert(make_pair(make_pair(nodep, attrType), varp)); + m_tableMap.emplace(make_pair(nodep, attrType), varp); return varp; } @@ -5956,7 +5955,7 @@ private: if (patmap.find(element) != patmap.end()) { patp->v3error("Assignment pattern key used multiple times: " << element); } else { - patmap.insert(make_pair(element, patp)); + patmap.emplace(element, patp); } element += range.leftToRightInc(); } diff --git a/src/VlcPoint.h b/src/VlcPoint.h index 36eea2feb..3d2ccba17 100644 --- a/src/VlcPoint.h +++ b/src/VlcPoint.h @@ -130,7 +130,7 @@ public: VlcPoint point(name, pointnum); point.countInc(count); m_points.push_back(point); - m_nameMap.insert(make_pair(point.name(), point.pointNum())); + m_nameMap.emplace(point.name(), point.pointNum()); } return pointnum; }