mirror of
https://github.com/verilator/verilator.git
synced 2026-09-02 18:58:51 +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:
+7
-6
@@ -178,12 +178,13 @@ private:
|
||||
const std::string type = AstCDType::typeToHold(items);
|
||||
const std::string name = "VlRandC<" + type + ", " + cvtToStr(items) + "ULL>";
|
||||
// Create or reuse (to avoid duplicates) randomization object dtype
|
||||
auto it = m_randcDtypes.find(name);
|
||||
if (it != m_randcDtypes.end()) return it->second;
|
||||
AstCDType* newp = new AstCDType{fl, name};
|
||||
v3Global.rootp()->typeTablep()->addTypesp(newp);
|
||||
m_randcDtypes.emplace(name, newp);
|
||||
return newp;
|
||||
const auto pair = m_randcDtypes.emplace(name, nullptr);
|
||||
if (pair.second) {
|
||||
AstCDType* newp = new AstCDType{fl, name};
|
||||
v3Global.rootp()->typeTablep()->addTypesp(newp);
|
||||
pair.first->second = newp;
|
||||
}
|
||||
return pair.first->second;
|
||||
}
|
||||
|
||||
AstVar* newRandcVarsp(AstVar* varp) {
|
||||
|
||||
Reference in New Issue
Block a user