mirror of
https://github.com/verilator/verilator.git
synced 2026-09-06 17:01:09 +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
-3
@@ -306,12 +306,12 @@ public:
|
||||
//######################################################################
|
||||
|
||||
void V3HierBlockPlan::add(const AstNodeModule* modp, const std::vector<AstVar*>& gparams) {
|
||||
const iterator it = m_blocks.find(modp);
|
||||
if (it == m_blocks.end()) {
|
||||
const auto pair = m_blocks.emplace(modp, nullptr);
|
||||
if (pair.second) {
|
||||
V3HierBlock* hblockp = new V3HierBlock{modp, gparams};
|
||||
UINFO(3, "Add " << modp->prettyNameQ() << " with " << gparams.size() << " parameters"
|
||||
<< std::endl);
|
||||
m_blocks.emplace(modp, hblockp);
|
||||
pair.first->second = hblockp;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user