mirror of
https://github.com/zeek/zeek.git
synced 2025-10-06 08:38:20 +00:00
Use .contains() instead of .find() or .count()
This commit is contained in:
parent
d20550f553
commit
b592b6c998
68 changed files with 201 additions and 207 deletions
|
@ -136,7 +136,7 @@ public:
|
|||
|
||||
// Returns true if at least one of the function bodies associated with
|
||||
// the function/hook/event handler of the given fname is not compilable.
|
||||
bool NotFullyCompilable(const std::string& fname) const { return not_fully_compilable.count(fname) > 0; }
|
||||
bool NotFullyCompilable(const std::string& fname) const { return not_fully_compilable.contains(fname); }
|
||||
|
||||
private:
|
||||
#include "zeek/script_opt/CPP/Attrs.h"
|
||||
|
|
|
@ -31,7 +31,7 @@ void CPPCompile::DeclareLambda(const LambdaExpr* l, const ProfileFunc* pf) {
|
|||
auto& ids = l->OuterIDs();
|
||||
|
||||
for ( auto lid : ids ) {
|
||||
if ( lambda_names.count(lid) > 0 ) {
|
||||
if ( lambda_names.contains(lid) ) {
|
||||
ASSERT(lambda_names[lid] == CaptureName(lid));
|
||||
}
|
||||
else
|
||||
|
@ -74,7 +74,7 @@ void CPPCompile::CreateFunction(const FuncTypePtr& ft, const ProfileFunc* pf, co
|
|||
|
||||
func_index[fname] = cast;
|
||||
|
||||
if ( ! l && casting_index.count(cast) == 0 ) {
|
||||
if ( ! l && ! casting_index.contains(cast) ) {
|
||||
casting_index[cast] = func_casting_glue.size();
|
||||
|
||||
DispatchInfo di;
|
||||
|
@ -314,7 +314,7 @@ void CPPCompile::GatherParamTypes(vector<string>& p_types, const FuncTypePtr& ft
|
|||
// Native types are always pass-by-value.
|
||||
p_types.emplace_back(tn);
|
||||
else {
|
||||
if ( param_id && pf->Assignees().count(param_id) > 0 )
|
||||
if ( param_id && pf->Assignees().contains(param_id) )
|
||||
// We modify the parameter.
|
||||
p_types.emplace_back(tn);
|
||||
else
|
||||
|
|
|
@ -138,7 +138,7 @@ void CPPCompile::Compile(bool report_uncompilable) {
|
|||
for ( const auto& l : accessed_lambdas ) {
|
||||
const auto& n = l->Name();
|
||||
const auto body = l->Ingredients()->Body().get();
|
||||
if ( lambda_ASTs.count(n) > 0 )
|
||||
if ( lambda_ASTs.contains(n) )
|
||||
// Reuse previous body.
|
||||
body_names[body] = body_names[lambda_ASTs[n]];
|
||||
else {
|
||||
|
@ -157,7 +157,7 @@ void CPPCompile::Compile(bool report_uncompilable) {
|
|||
lambda_ASTs.clear();
|
||||
for ( const auto& l : accessed_lambdas ) {
|
||||
const auto& n = l->Name();
|
||||
if ( lambda_ASTs.count(n) > 0 )
|
||||
if ( lambda_ASTs.contains(n) )
|
||||
continue;
|
||||
|
||||
CompileLambda(l, pfs->ExprProf(l).get());
|
||||
|
@ -196,12 +196,12 @@ bool CPPCompile::AnalyzeFuncBody(FuncInfo& fi, unordered_set<string>& filenames_
|
|||
string fn = body->GetLocationInfo()->FileName();
|
||||
|
||||
if ( ! analysis_options.allow_cond && ! fi.ShouldSkip() ) {
|
||||
if ( ! analysis_options.only_files.empty() && files_with_conditionals.count(fn) > 0 ) {
|
||||
if ( ! analysis_options.only_files.empty() && files_with_conditionals.contains(fn) ) {
|
||||
if ( report_uncompilable )
|
||||
reporter->Warning("%s cannot be compiled to C++ due to source file %s having conditional code",
|
||||
f->GetName().c_str(), fn.c_str());
|
||||
|
||||
else if ( filenames_reported_as_skipped.count(fn) == 0 ) {
|
||||
else if ( ! filenames_reported_as_skipped.contains(fn) ) {
|
||||
reporter->Warning("skipping compilation of files in %s due to presence of conditional code",
|
||||
fn.c_str());
|
||||
filenames_reported_as_skipped.emplace(fn);
|
||||
|
|
|
@ -148,11 +148,11 @@ string CPPCompile::GenExpr(const Expr* e, GenType gt, bool top_level) {
|
|||
string CPPCompile::GenNameExpr(const NameExpr* ne, GenType gt) {
|
||||
const auto& t = ne->GetType();
|
||||
auto n = ne->Id();
|
||||
bool is_global_var = global_vars.count(n) > 0;
|
||||
bool is_global_var = global_vars.contains(n);
|
||||
|
||||
if ( t->Tag() == TYPE_FUNC && ! is_global_var ) {
|
||||
auto func = n->Name();
|
||||
if ( globals.count(func) > 0 && pfs->BiFGlobals().count(n) == 0 )
|
||||
if ( globals.contains(func) && ! pfs->BiFGlobals().contains(n) )
|
||||
return GenericValPtrToGT(IDNameStr(n), t, gt);
|
||||
}
|
||||
|
||||
|
@ -277,8 +277,8 @@ string CPPCompile::GenCallExpr(const CallExpr* c, GenType gt, bool top_level) {
|
|||
auto id_name = f_id->Name();
|
||||
auto nargs = args_l->Exprs().length();
|
||||
|
||||
bool is_compiled = compiled_simple_funcs.count(id_name) > 0;
|
||||
bool was_compiled = hashed_funcs.count(id_name) > 0;
|
||||
bool is_compiled = compiled_simple_funcs.contains(id_name);
|
||||
bool was_compiled = hashed_funcs.contains(id_name);
|
||||
bool is_variadic = params->NumFields() == 1 && nargs != 1;
|
||||
|
||||
if ( ! is_async && ! is_variadic && (is_compiled || was_compiled) ) { // Can call directly.
|
||||
|
@ -303,10 +303,10 @@ string CPPCompile::GenCallExpr(const CallExpr* c, GenType gt, bool top_level) {
|
|||
//
|
||||
// If it is a BiF *that's also a global variable*, then
|
||||
// we need to look up the BiF version of the global.
|
||||
if ( pfs->BiFGlobals().count(f_id) == 0 )
|
||||
if ( ! pfs->BiFGlobals().contains(f_id) )
|
||||
gen += +"->AsFunc()";
|
||||
|
||||
else if ( accessed_globals.count(f_id) > 0 )
|
||||
else if ( accessed_globals.contains(f_id) )
|
||||
// The BiF version has an extra "_", per AddBiF(..., true).
|
||||
gen = globals[string(id_name) + "_"];
|
||||
}
|
||||
|
@ -1230,7 +1230,7 @@ string CPPCompile::GenField(const ExprPtr& rec, int field) {
|
|||
int mapping_slot;
|
||||
|
||||
auto rfm = record_field_mappings.find(rt);
|
||||
if ( rfm != record_field_mappings.end() && rfm->second.count(field) > 0 )
|
||||
if ( rfm != record_field_mappings.end() && rfm->second.contains(field) )
|
||||
// We're already tracking this field.
|
||||
mapping_slot = rfm->second[field];
|
||||
|
||||
|
@ -1269,7 +1269,7 @@ string CPPCompile::GenEnum(const TypePtr& t, const ValPtr& ev) {
|
|||
int mapping_slot;
|
||||
|
||||
auto evm = enum_val_mappings.find(et);
|
||||
if ( evm != enum_val_mappings.end() && evm->second.count(v) > 0 )
|
||||
if ( evm != enum_val_mappings.end() && evm->second.contains(v) )
|
||||
// We're already tracking this value.
|
||||
mapping_slot = evm->second[v];
|
||||
|
||||
|
|
|
@ -159,11 +159,11 @@ void CPPCompile::DeclareLocals(const ProfileFunc* pf, const IDPList* lambda_ids)
|
|||
auto ln = LocalName(l);
|
||||
auto cn = CaptureName(l);
|
||||
|
||||
if ( capture_names.count(cn) > 0 )
|
||||
if ( capture_names.contains(cn) )
|
||||
// No need to declare these, they're passed in as parameters.
|
||||
ln = cn;
|
||||
|
||||
else if ( params.count(l) == 0 && l->Offset() >= num_params ) { // Not a parameter, so must be a local.
|
||||
else if ( ! params.contains(l) && l->Offset() >= num_params ) { // Not a parameter, so must be a local.
|
||||
Emit("%s %s;", FullTypeName(l->GetType()), ln);
|
||||
did_decl = true;
|
||||
}
|
||||
|
|
|
@ -200,7 +200,7 @@ void CPPCompile::InitializeGlobals() {
|
|||
if ( ! ofiles.empty() && ! obj_matches_opt_files(g) )
|
||||
continue;
|
||||
|
||||
if ( accessed_globals.count(g) == 0 )
|
||||
if ( ! accessed_globals.contains(g) )
|
||||
continue;
|
||||
|
||||
auto ic = ginit.IC();
|
||||
|
@ -281,7 +281,7 @@ void CPPCompile::GenStandaloneActivation() {
|
|||
auto fname = BodyName(func);
|
||||
auto bname = Canonicalize(fname) + "_zf";
|
||||
|
||||
if ( compiled_funcs.count(bname) == 0 )
|
||||
if ( ! compiled_funcs.contains(bname) )
|
||||
// We didn't wind up compiling it.
|
||||
continue;
|
||||
|
||||
|
|
|
@ -82,7 +82,7 @@ void register_lambda__CPP(CPPStmtPtr body, p_hash_type hash, const char* name, T
|
|||
}
|
||||
|
||||
void register_scripts__CPP(p_hash_type h, void (*callback)()) {
|
||||
ASSERT(standalone_callbacks.count(h) == 0);
|
||||
ASSERT(! standalone_callbacks.contains(h));
|
||||
standalone_callbacks[h] = callback;
|
||||
}
|
||||
|
||||
|
|
|
@ -82,7 +82,7 @@ void CPPCompile::GenInitStmt(const InitStmt* init) {
|
|||
auto type_type = TypeType(t);
|
||||
auto type_ind = GenTypeName(t);
|
||||
|
||||
if ( locals.count(aggr.get()) == 0 ) {
|
||||
if ( ! locals.contains(aggr.get()) ) {
|
||||
// fprintf(stderr, "aggregate %s unused\n", obj_desc(aggr.get()).c_str());
|
||||
continue;
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@ void CPPTracker<T>::AddKey(IntrusivePtr<T> key, p_hash_type h) {
|
|||
if ( HasKey(key) )
|
||||
return;
|
||||
|
||||
if ( map2.count(h) == 0 ) {
|
||||
if ( ! map2.contains(h) ) {
|
||||
auto index = keys.size();
|
||||
keys.push_back(key);
|
||||
|
||||
|
|
|
@ -73,7 +73,7 @@ string CPPCompile::GenericValPtrToGT(const string& expr, const TypePtr& t, GenTy
|
|||
}
|
||||
|
||||
string CPPCompile::GenTypeName(const Type* t) {
|
||||
ASSERT(processed_types.count(TypeRep(t)) > 0);
|
||||
ASSERT(processed_types.contains(TypeRep(t)));
|
||||
return types.KeyName(TypeRep(t));
|
||||
}
|
||||
|
||||
|
|
|
@ -9,12 +9,12 @@ using namespace std;
|
|||
|
||||
void CPPCompile::CreateGlobal(const ID* g) {
|
||||
auto gn = string(g->Name());
|
||||
bool is_bif = pfs->BiFGlobals().count(g) > 0;
|
||||
bool is_bif = pfs->BiFGlobals().contains(g);
|
||||
|
||||
if ( accessed_globals.count(g) == 0 ) {
|
||||
if ( ! accessed_globals.contains(g) ) {
|
||||
// Only used in the context of calls. If it's compilable,
|
||||
// then we'll call it directly.
|
||||
if ( compilable_funcs.count(gn) > 0 ) {
|
||||
if ( compilable_funcs.contains(gn) ) {
|
||||
AddGlobal(gn, "zf");
|
||||
return;
|
||||
}
|
||||
|
@ -28,7 +28,7 @@ void CPPCompile::CreateGlobal(const ID* g) {
|
|||
if ( AddGlobal(gn, "gl") ) { // We'll be creating this global.
|
||||
Emit("IDPtr %s;", globals[gn]);
|
||||
|
||||
if ( accessed_events.count(gn) > 0 )
|
||||
if ( accessed_events.contains(gn) )
|
||||
// This is an event that's also used as a variable.
|
||||
Emit("EventHandlerPtr %s_ev;", globals[gn]);
|
||||
|
||||
|
@ -53,7 +53,7 @@ std::shared_ptr<CPP_InitInfo> CPPCompile::RegisterGlobal(const ID* g) {
|
|||
|
||||
auto gn = string(g->Name());
|
||||
|
||||
if ( globals.count(gn) == 0 ) {
|
||||
if ( ! globals.contains(gn) ) {
|
||||
// Create a name for it.
|
||||
(void)IDNameStr(g);
|
||||
|
||||
|
@ -103,12 +103,12 @@ void CPPCompile::AddBiF(const ID* b, bool is_var) {
|
|||
if ( AddGlobal(n, "bif") )
|
||||
Emit("Func* %s;", globals[n]);
|
||||
|
||||
ASSERT(BiFs.count(globals[n]) == 0);
|
||||
ASSERT(! BiFs.contains(globals[n]));
|
||||
BiFs[globals[n]] = bn;
|
||||
}
|
||||
|
||||
bool CPPCompile::AddGlobal(const string& g, const char* suffix) {
|
||||
if ( globals.count(g) > 0 )
|
||||
if ( globals.contains(g) )
|
||||
return false;
|
||||
|
||||
globals.emplace(g, GlobalName(g, suffix));
|
||||
|
@ -120,7 +120,7 @@ void CPPCompile::RegisterEvent(string ev_name) { body_events[body_name].emplace_
|
|||
const string& CPPCompile::IDNameStr(const ID* id) {
|
||||
if ( id->IsGlobal() ) {
|
||||
auto g = string(id->Name());
|
||||
if ( globals.count(g) == 0 )
|
||||
if ( ! globals.contains(g) )
|
||||
CreateGlobal(id);
|
||||
return globals[g];
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue