Cleanups related to PDict -> std::map replacements

This commit is contained in:
Jon Siwek 2019-08-13 19:54:42 -07:00
parent e6558d1f19
commit 87f85ecca1
18 changed files with 41 additions and 36 deletions

View file

@ -303,7 +303,7 @@ DFA_State_Cache::~DFA_State_Cache()
states.clear();
}
DFA_State* DFA_State_Cache::Lookup(const NFA_state_list& nfas, DigestStr& digest)
DFA_State* DFA_State_Cache::Lookup(const NFA_state_list& nfas, DigestStr* digest)
{
// We assume that state ID's don't exceed 10 digits, plus
// we allow one more character for the delimiter.
@ -332,9 +332,9 @@ DFA_State* DFA_State_Cache::Lookup(const NFA_state_list& nfas, DigestStr& digest
// HashKey because the data is copied into the key.
u_char digest_bytes[16];
internal_md5(id_tag, p - id_tag, digest_bytes);
digest = DigestStr(digest_bytes, 16);
*digest = DigestStr(digest_bytes, 16);
auto entry = states.find(digest);
auto entry = states.find(*digest);
if ( entry == states.end() )
{
++misses;
@ -342,14 +342,14 @@ DFA_State* DFA_State_Cache::Lookup(const NFA_state_list& nfas, DigestStr& digest
}
++hits;
digest.clear();
digest->clear();
return entry->second;
}
DFA_State* DFA_State_Cache::Insert(DFA_State* state, const DigestStr& digest)
DFA_State* DFA_State_Cache::Insert(DFA_State* state, DigestStr digest)
{
states.emplace(digest, state);
states.emplace(std::move(digest), state);
return state;
}
@ -432,7 +432,7 @@ bool DFA_Machine::StateSetToDFA_State(NFA_state_list* state_set,
DFA_State*& d, const EquivClass* ec)
{
DigestStr digest;
d = dfa_state_cache->Lookup(*state_set, digest);
d = dfa_state_cache->Lookup(*state_set, &digest);
if ( d )
return false;
@ -454,7 +454,7 @@ bool DFA_Machine::StateSetToDFA_State(NFA_state_list* state_set,
}
DFA_State* ds = new DFA_State(state_count++, ec, state_set, accept);
d = dfa_state_cache->Insert(ds, digest);
d = dfa_state_cache->Insert(ds, std::move(digest));
return true;
}

View file

@ -75,10 +75,10 @@ public:
~DFA_State_Cache();
// If the caller stores the handle, it has to call Ref() on it.
DFA_State* Lookup(const NFA_state_list& nfa_states, DigestStr& digest);
DFA_State* Lookup(const NFA_state_list& nfa_states, DigestStr* digest);
// Takes ownership of both; hash is the one returned by Lookup().
DFA_State* Insert(DFA_State* state, const DigestStr& digest);
// Takes ownership of state; digest is the one returned by Lookup().
DFA_State* Insert(DFA_State* state, DigestStr digest);
int NumEntries() const { return states.size(); }

View file

@ -51,7 +51,7 @@ void lookup_global_symbols_regex(const string& orig_regex, vector<ID*>& matches,
}
Scope* global = global_scope();
auto syms = global->Vars();
const auto& syms = global->Vars();
ID* nextid;
for ( const auto& sym : syms )

View file

@ -92,7 +92,7 @@ void EventRegistry::SetErrorHandler(const string& name)
return;
}
reporter->InternalWarning(
"unknown event handler '%s' in SetErrorHandler()", name.c_str());
reporter->InternalWarning("unknown event handler '%s' in SetErrorHandler()",
name.c_str());
}

View file

@ -4347,7 +4347,7 @@ LambdaExpr::LambdaExpr(std::unique_ptr<function_ingredients> arg_ing,
my_name = "lambda_<" + std::to_string(h[0]) + ">";
auto fullname = make_full_var_name(current_module.data(), my_name.data());
auto id = global_scope()->Lookup(fullname.data());
auto id = global_scope()->Lookup(fullname);
if ( id )
// Just try again to make a unique lambda name. If two peer
@ -4413,7 +4413,7 @@ EventExpr::EventExpr(const char* arg_name, ListExpr* arg_args)
name = arg_name;
args = arg_args;
EventHandler* h = event_registry->Lookup(name.c_str());
EventHandler* h = event_registry->Lookup(name);
if ( ! h )
{
h = new EventHandler(name.c_str());

View file

@ -122,7 +122,7 @@ BroType* OpaqueVal::UnserializeType(const broker::data& data)
if ( ! name )
return nullptr;
ID* id = global_scope()->Lookup(name->c_str());
ID* id = global_scope()->Lookup(*name);
if ( ! id )
return nullptr;

View file

@ -198,7 +198,7 @@ string Specific_RE_Matcher::LookupDef(const string& def)
{
const auto& iter = defs.find(def);
if ( iter != defs.end() )
return iter->first;
return iter->second;
return string();
}
@ -418,7 +418,10 @@ unsigned int Specific_RE_Matcher::MemoryAllocation() const
size += pad_size(sizeof(CCL*) * ccl_dict.size());
for ( const auto& entry : ccl_dict )
{
size += padded_sizeof(std::string) + pad_size(sizeof(std::string::value_type) * entry.first.size());
size += entry.second->MemoryAllocation();
}
for ( const auto& entry : defs )
{

View file

@ -128,7 +128,7 @@ ID* lookup_ID(const char* name, const char* curr_module, bool no_global,
for ( int i = scopes.length() - 1; i >= 0; --i )
{
ID* id = scopes[i]->Lookup(fullname.c_str());
ID* id = scopes[i]->Lookup(fullname);
if ( id )
{
if ( need_export && ! id->IsExport() && ! in_debug )
@ -144,7 +144,7 @@ ID* lookup_ID(const char* name, const char* curr_module, bool no_global,
! same_module_only) )
{
string globalname = make_full_var_name(GLOBAL_MODULE_NAME, name);
ID* id = global_scope()->Lookup(globalname.c_str());
ID* id = global_scope()->Lookup(globalname);
if ( id )
{
Ref(id);

View file

@ -239,7 +239,7 @@ void ProfileLogger::Log()
// Script-level state.
unsigned int size, mem = 0;
auto globals = global_scope()->Vars();
const auto& globals = global_scope()->Vars();
if ( expensive )
{

View file

@ -1799,7 +1799,7 @@ BroType* merge_types(const BroType* t1, const BroType* t2)
// Doing a lookup here as a roundabout way of ref-ing t1, without
// changing the function params which has t1 as const and also
// (potentially) avoiding a pitfall mentioned earlier about clones.
auto id = global_scope()->Lookup(t1->GetName().data());
auto id = global_scope()->Lookup(t1->GetName());
if ( id && id->AsType() && id->AsType()->Tag() == TYPE_ENUM )
// It should make most sense to return the real type here rather

View file

@ -264,7 +264,7 @@ public:
virtual unsigned MemoryAllocation() const;
void SetName(const string& arg_name) { name = arg_name; }
string GetName() const { return name; }
const string& GetName() const { return name; }
typedef std::map<std::string, std::set<BroType*> > TypeAliasMap;

View file

@ -351,7 +351,7 @@ struct val_converter {
if ( ! name )
return nullptr;
auto id = global_scope()->Lookup(name->c_str());
auto id = global_scope()->Lookup(*name);
if ( ! id )
return nullptr;
@ -703,7 +703,7 @@ struct type_checker {
if ( ! name )
return false;
auto id = global_scope()->Lookup(name->c_str());
auto id = global_scope()->Lookup(*name);
if ( ! id )
return false;

View file

@ -407,7 +407,7 @@ bool Manager::PublishIdentifier(std::string topic, std::string id)
if ( peer_count == 0 )
return true;
ID* i = global_scope()->Lookup(id.c_str());
ID* i = global_scope()->Lookup(id);
if ( ! i )
return false;
@ -998,7 +998,7 @@ void Manager::ProcessEvent(const broker::topic& topic, broker::zeek::Event ev)
DBG_LOG(DBG_BROKER, "Process event: %s %s",
name.data(), RenderMessage(args).data());
++statistics.num_events_incoming;
auto handler = event_registry->Lookup(name.data());
auto handler = event_registry->Lookup(name);
if ( ! handler )
return;
@ -1240,7 +1240,7 @@ bool Manager::ProcessIdentifierUpdate(broker::zeek::IdentifierUpdate iu)
++statistics.num_ids_incoming;
auto id_name = std::move(iu.id_name());
auto id_value = std::move(iu.id_value());
auto id = global_scope()->Lookup(id_name.c_str());
auto id = global_scope()->Lookup(id_name);
if ( ! id )
{

View file

@ -33,7 +33,7 @@ Manager::~Manager()
for ( MIMEMap::iterator i = mime_types.begin(); i != mime_types.end(); i++ )
delete i->second;
// Have to assume that too much of Bro has been shutdown by this point
// Have to assume that too much of Zeek has been shutdown by this point
// to do anything more than reclaim memory.
for ( const auto& entry : id_map )
delete entry.second;
@ -58,6 +58,8 @@ void Manager::InitMagic()
void Manager::Terminate()
{
vector<string> keys;
keys.reserve(id_map.size());
for ( const auto& entry : id_map )
keys.push_back(entry.first);
@ -406,8 +408,8 @@ bool Manager::RemoveFile(const string& file_id)
f->EndOfFile();
delete f;
id_map.erase(file_id);
id_map.erase(file_id);
ignored.erase(file_id);
return true;
}

View file

@ -1852,7 +1852,7 @@ bool Manager::SendEvent(ReaderFrontend* reader, const string& name, const int nu
return false;
}
EventHandler* handler = event_registry->Lookup(name.c_str());
EventHandler* handler = event_registry->Lookup(name);
if ( handler == 0 )
{
Warning(i, "Event %s not found", name.c_str());

View file

@ -28,7 +28,7 @@ Config::Config(ReaderFrontend *frontend) : ReaderBackend(frontend)
fail_on_file_problem = false;
// find all option names and their types.
auto globals = global_scope()->Vars();
const auto& globals = global_scope()->Vars();
for ( const auto& entry : globals )
{

View file

@ -1895,7 +1895,7 @@ function reading_traces%(%): bool
function global_sizes%(%): var_sizes
%{
TableVal* sizes = new TableVal(var_sizes);
auto globals = global_scope()->Vars();
const auto& globals = global_scope()->Vars();
for ( const auto& global : globals )
{
@ -1923,7 +1923,7 @@ function global_sizes%(%): var_sizes
function global_ids%(%): id_table
%{
TableVal* ids = new TableVal(id_table);
auto globals = global_scope()->Vars();
const auto& globals = global_scope()->Vars();
for ( const auto& global : globals )
{