mirror of
https://github.com/verilator/verilator.git
synced 2026-10-06 01:54:01 +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:
@@ -155,10 +155,9 @@ class SchedGraphBuilder final : public VNVisitor {
|
||||
// rst), so we use a hash map to get the unique SchedSenVertex. (Note: This creates
|
||||
// separate vertices for ET_CHANGED and ET_HYBRID over the same expression, but that is
|
||||
// OK for now).
|
||||
auto it = m_senVertices.find(*senItemp);
|
||||
|
||||
const auto pair = m_senVertices.emplace(*senItemp, nullptr);
|
||||
// If it does not exist, create it
|
||||
if (it == m_senVertices.end()) {
|
||||
if (pair.second) {
|
||||
// Create the vertex
|
||||
SchedSenVertex* const vtxp = new SchedSenVertex{m_graphp, senItemp};
|
||||
|
||||
@@ -168,11 +167,11 @@ class SchedGraphBuilder final : public VNVisitor {
|
||||
});
|
||||
|
||||
// Store back to hash map so we can find it next time
|
||||
it = m_senVertices.emplace(*senItemp, vtxp).first;
|
||||
pair.first->second = vtxp;
|
||||
}
|
||||
|
||||
// Cache sensitivity vertex
|
||||
senItemp->user1p(it->second);
|
||||
senItemp->user1p(pair.first->second);
|
||||
}
|
||||
return senItemp->user1u().to<SchedSenVertex*>();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user