mirror of
https://github.com/verilator/verilator.git
synced 2026-10-06 10:03:44 +02:00
Avoid double traversal of maps
The typical find/if-not-exists-insert pattern can be achieved with 1 lookup instead of 2 using emplace with a sentinel value. Also maps value initialize their values when inserted with the [] operator, this is defined and so there is no need to explicitly insert zeroes for integer values.
This commit is contained in:
+3
-8
@@ -495,14 +495,9 @@ public:
|
||||
V3List<OrderMoveVertex*>& readyVertices() { return m_readyVertices; }
|
||||
static OrderMoveDomScope* findCreate(const AstSenTree* domainp, const AstScope* scopep) {
|
||||
const DomScopeKey key = std::make_pair(domainp, scopep);
|
||||
const auto iter = s_dsMap.find(key);
|
||||
if (iter != s_dsMap.end()) {
|
||||
return iter->second;
|
||||
} else {
|
||||
OrderMoveDomScope* domScopep = new OrderMoveDomScope{domainp, scopep};
|
||||
s_dsMap.emplace(key, domScopep);
|
||||
return domScopep;
|
||||
}
|
||||
const auto pair = s_dsMap.emplace(key, nullptr);
|
||||
if (pair.second) pair.first->second = new OrderMoveDomScope{domainp, scopep};
|
||||
return pair.first->second;
|
||||
}
|
||||
string name() const {
|
||||
return string{"MDS:"} + " d=" + cvtToHex(domainp()) + " s=" + cvtToHex(scopep());
|
||||
|
||||
Reference in New Issue
Block a user