mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 14:48:21 +00:00
Some minor c++ modernization in EnumType methods
This commit is contained in:
parent
c22e54604f
commit
08101eb372
2 changed files with 8 additions and 14 deletions
15
src/Type.cc
15
src/Type.cc
|
@ -1617,12 +1617,10 @@ zeek_int_t EnumType::Lookup(const string& module_name, const char* name) const {
|
|||
}
|
||||
|
||||
zeek_int_t EnumType::Lookup(const string& full_name) const {
|
||||
auto pos = names.find(full_name.c_str());
|
||||
|
||||
if ( pos == names.end() )
|
||||
return -1;
|
||||
else
|
||||
if ( auto pos = names.find(full_name.c_str()); pos != names.end() )
|
||||
return pos->second;
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
const char* EnumType::Lookup(zeek_int_t value) const {
|
||||
|
@ -1641,16 +1639,13 @@ EnumType::enum_name_list EnumType::Names() const {
|
|||
}
|
||||
|
||||
const EnumValPtr& EnumType::GetEnumVal(zeek_int_t i) {
|
||||
auto it = vals.find(i);
|
||||
if ( auto it = vals.find(i); it != vals.end() )
|
||||
return it->second;
|
||||
|
||||
if ( it == vals.end() ) {
|
||||
auto ev = make_intrusive<EnumVal>(IntrusivePtr{NewRef{}, this}, i);
|
||||
return vals.emplace(i, std::move(ev)).first->second;
|
||||
}
|
||||
|
||||
return it->second;
|
||||
}
|
||||
|
||||
void EnumType::DoDescribe(ODesc* d) const {
|
||||
auto t = Tag();
|
||||
|
||||
|
|
|
@ -869,8 +869,7 @@ protected:
|
|||
// Whether any of the elements of the enum were added via redef's.
|
||||
bool has_redefs = false;
|
||||
|
||||
using ValMap = std::unordered_map<zeek_int_t, EnumValPtr>;
|
||||
ValMap vals;
|
||||
std::unordered_map<zeek_int_t, EnumValPtr> vals;
|
||||
|
||||
// The counter is initialized to 0 and incremented on every implicit
|
||||
// auto-increment name that gets added (thus its > 0 if
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue