Minor optimization to get_attribute_bool

This commit is contained in:
Matthew Daiter 2019-05-07 22:04:28 -05:00
parent 752553d8e9
commit 6e629d2895
1 changed files with 8 additions and 4 deletions

View File

@ -218,15 +218,19 @@ void RTLIL::AttrObject::set_bool_attribute(RTLIL::IdString id, bool value)
{ {
if (value) if (value)
attributes[id] = RTLIL::Const(1); attributes[id] = RTLIL::Const(1);
else if (attributes.count(id)) else {
attributes.erase(id); const auto it = attributes.find(id);
if (it != attributes.end())
attributes.erase(it);
}
} }
bool RTLIL::AttrObject::get_bool_attribute(RTLIL::IdString id) const bool RTLIL::AttrObject::get_bool_attribute(RTLIL::IdString id) const
{ {
if (attributes.count(id) == 0) const auto it = attributes.find(id);
if (it == attributes.end())
return false; return false;
return attributes.at(id).as_bool(); return it->second.as_bool();
} }
void RTLIL::AttrObject::set_strpool_attribute(RTLIL::IdString id, const pool<string> &data) void RTLIL::AttrObject::set_strpool_attribute(RTLIL::IdString id, const pool<string> &data)