Merge remote-tracking branch 'origin/topic/timw/readability-container-contains'

* origin/topic/timw/readability-container-contains:
  Fix a few more random clang-tidy findings
  Use std::numbers::pi instead of hard-coded value
  Use std::scoped_lock instead of std::lock_guard
  Use .contains() instead of .find() or .count()
This commit is contained in:
Tim Wojtulewicz 2025-09-02 11:47:44 -07:00
commit deeca84332
74 changed files with 225 additions and 220 deletions

View file

@ -3,6 +3,7 @@ Checks: [-*,
performance-*,
modernize-*,
readability-isolate-declaration,
readability-container-contains,
# Enable a very limited number of the cppcoreguidelines checkers.
# See the notes for some of the rest of them below.

10
CHANGES
View file

@ -1,3 +1,13 @@
8.1.0-dev.490 | 2025-09-02 11:47:44 -0700
* Fix a few more random clang-tidy findings (Tim Wojtulewicz, Corelight)
* Use std::numbers::pi instead of hard-coded value (Tim Wojtulewicz, Corelight)
* Use std::scoped_lock instead of std::lock_guard (Tim Wojtulewicz, Corelight)
* Use .contains() instead of .find() or .count() (Tim Wojtulewicz, Corelight)
8.1.0-dev.484 | 2025-08-29 21:53:19 -0700
* Bump zeek-testing-cluster to pull in WebSocket TLS updates (Christian Kreibich, Corelight)

View file

@ -1 +1 @@
8.1.0-dev.484
8.1.0-dev.490

View file

@ -473,20 +473,20 @@ void DNS_Mgr::Done() {
}
void DNS_Mgr::RegisterSocket(int fd, bool read, bool write) {
if ( read && socket_fds.count(fd) == 0 ) {
if ( read && ! socket_fds.contains(fd) ) {
socket_fds.insert(fd);
iosource_mgr->RegisterFd(fd, this, IOSource::READ);
}
else if ( ! read && socket_fds.count(fd) != 0 ) {
else if ( ! read && socket_fds.contains(fd) ) {
socket_fds.erase(fd);
iosource_mgr->UnregisterFd(fd, this, IOSource::READ);
}
if ( write && write_socket_fds.count(fd) == 0 ) {
if ( write && ! write_socket_fds.contains(fd) ) {
write_socket_fds.insert(fd);
iosource_mgr->RegisterFd(fd, this, IOSource::WRITE);
}
else if ( ! write && write_socket_fds.count(fd) != 0 ) {
else if ( ! write && write_socket_fds.contains(fd) ) {
write_socket_fds.erase(fd);
iosource_mgr->UnregisterFd(fd, this, IOSource::WRITE);
}
@ -1323,7 +1323,7 @@ double DNS_Mgr::GetNextTimeout() {
}
void DNS_Mgr::ProcessFd(int fd, int flags) {
if ( socket_fds.count(fd) != 0 ) {
if ( socket_fds.contains(fd) ) {
int read_fd = (flags & IOSource::ProcessFlags::READ) != 0 ? fd : ARES_SOCKET_BAD;
int write_fd = (flags & IOSource::ProcessFlags::WRITE) != 0 ? fd : ARES_SOCKET_BAD;
ares_process_fd(channel, read_fd, write_fd);

View file

@ -148,7 +148,7 @@ bool DebugLogger::CheckStreams(const std::set<std::string>& plugin_names) {
if ( ! stream.starts_with("plugin-") )
continue;
if ( available_plugin_streams.count(stream) == 0 ) {
if ( ! available_plugin_streams.contains(stream) ) {
reporter->Error("No plugin debug stream '%s' found", stream.c_str());
ok = false;
}
@ -180,7 +180,7 @@ void DebugLogger::Log(DebugStream stream, const char* fmt, ...) {
void DebugLogger::Log(const plugin::Plugin& plugin, const char* fmt, ...) {
if ( ! all ) {
std::string tok = PluginStreamName(plugin.Name());
if ( enabled_streams.find(tok) == enabled_streams.end() )
if ( ! enabled_streams.contains(tok) )
return;
}

View file

@ -55,7 +55,7 @@ EventHandler* EventRegistry::Lookup(std::string_view name) {
}
bool EventRegistry::NotOnlyRegisteredFromScript(std::string_view name) {
return not_only_from_script.count(std::string(name)) > 0;
return not_only_from_script.contains(std::string(name));
}
EventRegistry::string_list EventRegistry::Match(RE_Matcher* pattern) {
@ -174,12 +174,12 @@ namespace {
class EventMetadataTypeRejector : public detail::TraversalCallback {
public:
detail::TraversalCode PreType(const Type* t) override {
if ( visited.count(t) > 0 )
if ( visited.contains(t) )
return detail::TC_ABORTSTMT;
visited.insert(t);
if ( reject.count(t->Tag()) )
if ( reject.contains(t->Tag()) )
rejected.push_back(t);
return detail::TC_CONTINUE;

View file

@ -732,7 +732,7 @@ void ValTraceMgr::TraceEventValues(std::shared_ptr<EventTrace> et, const zeek::A
// remember them so we can catch uses of them in future events.
for ( auto i = num_vals; i < vals.size(); ++i ) {
processed_vals.insert(vals[i].get());
ASSERT(val_names.count(vals[i].get()) > 0);
ASSERT(val_names.contains(vals[i].get()));
}
}
@ -794,8 +794,8 @@ void ValTraceMgr::NewVal(ValPtr v) {
}
void ValTraceMgr::ValUsed(const ValPtr& v) {
ASSERT(val_names.count(v.get()) > 0);
if ( processed_vals.count(v.get()) > 0 )
ASSERT(val_names.contains(v.get()));
if ( processed_vals.contains(v.get()) )
// We saw this value when processing a previous event.
globals.insert(v.get());
}
@ -818,17 +818,17 @@ void ValTraceMgr::AssessChange(const ValTrace* vt, const ValTrace* prev_vt) {
bool needs_lhs = d->NeedsLHS();
bool is_first_def = false;
if ( needs_lhs && val_names.count(v) == 0 ) {
if ( needs_lhs && ! val_names.contains(v) ) {
TrackVar(v);
is_first_def = true;
}
ASSERT(val_names.count(v) > 0);
ASSERT(val_names.contains(v));
// The "/" in the following is just to have a delimiter
// to make sure the string is unambiguous.
auto full_delta = val_names[v] + "/" + rhs;
if ( previous_deltas.count(full_delta) > 0 )
if ( previous_deltas.contains(full_delta) )
continue;
previous_deltas.insert(std::move(full_delta));
@ -849,7 +849,7 @@ void ValTraceMgr::TrackVar(const Val* v) {
std::string ValTraceMgr::GenValName(const ValPtr& v) {
if ( IsAggr(v->GetType()) && ! IsUnspecifiedAggregate(v) ) { // Aggregate shouldn't exist; create it
ASSERT(val_map.count(v.get()) == 0);
ASSERT(! val_map.contains(v.get()));
NewVal(v);
return val_names[v.get()];
}
@ -1012,7 +1012,7 @@ void EventTraceMgr::Generate() {
}
void EventTraceMgr::StartEvent(const ScriptFunc* ev, const zeek::Args* args) {
if ( script_events.count(ev->GetName()) > 0 )
if ( script_events.contains(ev->GetName()) )
return;
auto nt = run_state::network_time;
@ -1029,7 +1029,7 @@ void EventTraceMgr::StartEvent(const ScriptFunc* ev, const zeek::Args* args) {
}
void EventTraceMgr::EndEvent(const ScriptFunc* ev, const zeek::Args* args) {
if ( script_events.count(ev->GetName()) > 0 )
if ( script_events.contains(ev->GetName()) )
return;
if ( run_state::network_time > 0.0 && ev->GetName() != "zeek_init" )

View file

@ -354,7 +354,7 @@ public:
// Returns true if the script variable associated with the given value
// needs to be global (because it's used across multiple events).
bool IsGlobal(const ValPtr& v) const { return globals.count(v.get()) > 0; }
bool IsGlobal(const ValPtr& v) const { return globals.contains(v.get()); }
// Returns or sets the "base time" from which eligible times are
// transformed into offsets rather than maintained as absolute

View file

@ -2999,7 +2999,7 @@ RecordConstructorExpr::RecordConstructorExpr(RecordTypePtr known_rt, ListExprPtr
auto n = known_rt->NumFields();
for ( i = 0; i < n; ++i )
if ( fields_seen.count(i) == 0 ) {
if ( ! fields_seen.contains(i) ) {
const auto td_i = known_rt->FieldDecl(i);
if ( IsAggr(td_i->type) )
// These are always initialized.
@ -4307,7 +4307,7 @@ bool LambdaExpr::CheckCaptures(StmtPtr when_parent) {
// already been an error message.
continue;
if ( capture_is_matched.count(cid) > 0 ) {
if ( capture_is_matched.contains(cid) ) {
auto msg = util::fmt("%s listed multiple times in capture", cid->Name());
if ( when_parent )
when_parent->Error(msg);
@ -4326,7 +4326,7 @@ bool LambdaExpr::CheckCaptures(StmtPtr when_parent) {
}
for ( auto id : outer_ids )
if ( outer_is_matched.count(id) == 0 ) {
if ( ! outer_is_matched.contains(id) ) {
auto msg = util::fmt("%s is used inside %s but not captured", id->Name(), desc);
if ( when_parent )
when_parent->Error(msg);
@ -4338,7 +4338,7 @@ bool LambdaExpr::CheckCaptures(StmtPtr when_parent) {
for ( const auto& c : *captures ) {
auto cid = c.Id().get();
if ( cid && capture_is_matched.count(cid) == 0 ) {
if ( cid && ! capture_is_matched.contains(cid) ) {
auto msg = util::fmt("%s is captured but not used inside %s", cid->Name(), desc);
if ( when_parent )
when_parent->Error(msg);

View file

@ -68,7 +68,7 @@ bool LoadPolicyFileText(const char* policy_filename, const std::optional<std::st
if ( ! policy_filename )
return true;
if ( policy_files.find(policy_filename) != policy_files.end() )
if ( policy_files.contains(policy_filename) )
debug_msg("Policy file %s already loaded\n", policy_filename);
PolicyFile* pf = new PolicyFile;

View file

@ -292,12 +292,8 @@ private:
__attribute__((format(printf, 4, 5)));
;
void UpdateWeirdStats(const char* name);
inline bool WeirdOnSamplingWhiteList(const char* name) {
return weird_sampling_whitelist.find(name) != weird_sampling_whitelist.end();
}
inline bool WeirdOnGlobalList(const char* name) {
return weird_sampling_global_list.find(name) != weird_sampling_global_list.end();
}
inline bool WeirdOnSamplingWhiteList(const char* name) { return weird_sampling_whitelist.contains(name); }
inline bool WeirdOnGlobalList(const char* name) { return weird_sampling_global_list.contains(name); }
bool PermitNetWeird(const char* name);
bool PermitFlowWeird(const char* name, const IPAddr& o, const IPAddr& r);
bool PermitExpiredConnWeird(const char* name, const RecordVal& conn_id);

View file

@ -334,7 +334,7 @@ bool RuleMatcher::ReadFiles(const std::vector<SignatureFile>& files) {
}
void RuleMatcher::AddRule(Rule* rule) {
if ( rules_by_id.find(rule->ID()) != rules_by_id.end() ) {
if ( rules_by_id.contains(rule->ID()) ) {
rules_error("rule defined twice");
return;
}
@ -602,7 +602,7 @@ bool RuleMatcher::AllRulePatternsMatched(const Rule* r, MatchPos matchpos, const
// Check whether all patterns of the rule have matched.
for ( const auto& pattern : r->patterns ) {
if ( ams.find(pattern->id) == ams.end() )
if ( ! ams.contains(pattern->id) )
return false;
// See if depth is satisfied.

View file

@ -158,7 +158,7 @@ void ScriptCoverageManager::TrackUsage(const Location* loc, std::string desc, ui
pair<string, string> location_desc(location_info.Description(), desc);
if ( usage_map.find(location_desc) != usage_map.end() )
if ( usage_map.contains(location_desc) )
usage_map[location_desc] += cnt;
else
usage_map[location_desc] = cnt;

View file

@ -122,10 +122,10 @@ ScriptProfileMgr::~ScriptProfileMgr() {
BiF_stats.AddIn(p);
}
else {
ASSERT(body_to_func.count(o) > 0);
ASSERT(body_to_func.contains(o));
auto func = body_to_func[o];
if ( func_stats.count(func) == 0 )
if ( ! func_stats.contains(func) )
func_stats[func] = ScriptProfileStats(func->GetName());
func_stats[func].AddIn(p);

View file

@ -59,7 +59,7 @@ public:
}
TraversalCode PreType(const Type* t) override {
if ( types_seen.count(t) > 0 )
if ( types_seen.contains(t) )
return TC_ABORTSTMT;
types_seen.insert(t);

View file

@ -415,7 +415,7 @@ static bool is_supported_index_type(const TypePtr& t, const char** tname, std::u
// Handle recursive calls as good: If they turn out not
// to be, that should've been discovered further down.
if ( seen.count(t) > 0 )
if ( seen.contains(t) )
return true;
seen.insert(t);
@ -1006,7 +1006,7 @@ class RecordType::CreationInitsOptimizer : public detail::TraversalCallback {
public:
detail::TraversalCode PreTypedef(const detail::ID* id) override {
const auto& t = id->GetType();
if ( analyzed_types.count(t) > 0 )
if ( analyzed_types.contains(t) )
return detail::TC_ABORTSTMT;
analyzed_types.emplace(t);
@ -1102,7 +1102,7 @@ void RecordType::AddField(unsigned int field, const TypeDecl* td) {
// We defer error-checking until here so that we can keep deferred_inits
// and managed_fields correctly tracking the associated fields.
if ( field_ids.count(td->id) != 0 ) {
if ( field_ids.contains(td->id) ) {
reporter->Error("duplicate field '%s' found in record definition", td->id);
deferred_inits.push_back(nullptr);
return;
@ -1168,7 +1168,7 @@ void RecordType::AddField(unsigned int field, const TypeDecl* td) {
deferred_inits.push_back(std::move(init));
}
bool RecordType::HasField(const char* field) const { return field_ids.count(field) != 0; }
bool RecordType::HasField(const char* field) const { return field_ids.contains(field); }
ValPtr RecordType::FieldDefault(int field) const {
const TypeDecl* td = FieldDecl(field);
@ -1654,8 +1654,7 @@ void EnumType::CheckAndAddName(const string& module_name, const char* name, zeek
// we can define an enum both in a *.bif and *.zeek for avoiding
// cyclic dependencies.
if ( ! id->IsEnumConst() || (id->HasVal() && val != id->GetVal()->AsEnum()) ||
GetName() != id->GetType()->GetName() ||
(names.find(fullname) != names.end() && names[fullname] != val) ) {
GetName() != id->GetType()->GetName() || (names.contains(fullname) && names[fullname] != val) ) {
auto cl = detail::GetCurrentLocation();
reporter->PushLocation(&cl, id->GetLocationInfo());
reporter->Error("conflicting definition of enum value '%s' in type '%s'", fullname.data(),
@ -1668,7 +1667,7 @@ void EnumType::CheckAndAddName(const string& module_name, const char* name, zeek
AddNameInternal(module_name, name, val, is_export);
if ( vals.find(val) == vals.end() )
if ( ! vals.contains(val) )
vals[val] = make_intrusive<EnumVal>(IntrusivePtr{NewRef{}, this}, val);
if ( ! id->HasVal() )
@ -1694,7 +1693,7 @@ void EnumType::AddNameInternal(const string& full_name, zeek_int_t val) {
names[full_name] = val;
rev_names[val] = full_name;
if ( vals.find(val) == vals.end() )
if ( ! vals.contains(val) )
vals[val] = make_intrusive<EnumVal>(IntrusivePtr{NewRef{}, this}, val);
}
@ -2031,11 +2030,11 @@ bool same_type(const Type& arg_t1, const Type& arg_t2, bool is_init, bool match_
// If we get to here, then we're dealing with a type with
// subtypes, and thus potentially recursive.
if ( analyzed_types.count(t1) > 0 || analyzed_types.count(t2) > 0 ) {
if ( analyzed_types.contains(t1) || analyzed_types.contains(t2) ) {
// We've analyzed at least one of the types previously.
// Avoid infinite recursion.
if ( analyzed_types.count(t1) > 0 && analyzed_types.count(t2) > 0 )
if ( analyzed_types.contains(t1) && analyzed_types.contains(t2) )
// We've analyzed them both. In theory, this
// could happen while the types are still different.
// Checking for that is a pain - we could do so

View file

@ -1532,7 +1532,7 @@ static void find_nested_record_types(const TypePtr& t, std::set<RecordType*>* fo
case TYPE_RECORD: {
auto rt = t->AsRecordType();
if ( analyzed_records->count(rt) > 0 )
if ( analyzed_records->contains(rt) )
return;
analyzed_records->insert(rt);
@ -2882,7 +2882,7 @@ void TableVal::RebuildParseTimeTables() {
for ( auto& [tv, ptts] : parse_time_table_states ) {
auto* tt = tv->table_type.get();
if ( table_types.count(tt) == 0 ) {
if ( ! table_types.contains(tt) ) {
tt->RegenerateHash();
table_types.insert(tt);
}
@ -4041,7 +4041,7 @@ unsigned int Val::Footprint(std::unordered_set<const Val*>* analyzed_vals) const
// We only need to check containers for possible recursion, as there's
// no way to construct a cycle using only non-aggregates.
if ( is_aggr ) {
if ( analyzed_vals->count(this) > 0 )
if ( analyzed_vals->contains(this) )
// Footprint is 1 for generating a cycle.
return 1;

View file

@ -49,7 +49,7 @@ bool IRC_Analyzer::IsValidClientCommand(const std::string& command) {
"SETNAME", "SILENCE", "SQUERY", "SQUIT", "STATS", "SUMMON", "TIME", "TOPIC", "TRACE",
"USER", "USERHOST", "USERS", "VERSION", "WALLOPS", "WHO", "WHOIS", "WHOWAS", "STARTTLS"};
return validCommands.find(command) != validCommands.end();
return validCommands.contains(command);
}
void IRC_Analyzer::DeliverStream(int length, const u_char* line, bool orig) {

View file

@ -31,7 +31,7 @@ refine connection SMB_Conn += {
function get_is_file_a_pipe(id: uint16): bool
%{
if ( is_file_a_pipe.count(id) > 0 )
if ( is_file_a_pipe.contains(id) )
{
bool is_pipe = is_file_a_pipe.at(id);
is_file_a_pipe.erase(id);

View file

@ -1072,7 +1072,7 @@ bool SetIterator::DoUnserializeData(BrokerDataView data) {
// This is not perfect, as there's no guarantee that the restored
// container will list the elements in the same order. But it's as
// good as we can do, and it should generally work out.
if ( x->find((*v)[1]) == x->end() )
if ( ! x->contains((*v)[1]) )
return false;
dat = *x;
@ -1097,7 +1097,7 @@ bool TableIterator::DoUnserializeData(BrokerDataView data) {
// This is not perfect, as there's no guarantee that the restored
// container will list the elements in the same order. But it's as
// good as we can do, and it should generally work out.
if ( x->find((*v)[1]) == x->end() )
if ( ! x->contains((*v)[1]) )
return false;
dat = *x;

View file

@ -149,7 +149,7 @@ public:
// arrivals (a push, is_push == true) and departures (a pull, is_push ==
// false) as they happen. Note that this must not touch Zeek-side Vals.
void Observe(const broker::endpoint_id& peer, bool is_push) {
std::lock_guard<std::mutex> lock(mutex);
std::scoped_lock<std::mutex> lock(mutex);
auto it = stats_map.find(peer);
if ( it == stats_map.end() ) {
@ -186,7 +186,7 @@ public:
// Updates the internal table[string] of BrokerPeeringStats and returns it.
const zeek::TableValPtr& GetPeeringStatsTable() {
std::lock_guard<std::mutex> lock(mutex);
std::scoped_lock<std::mutex> lock(mutex);
for ( auto it = stats_map.begin(); it != stats_map.end(); ) {
auto& peer = it->first;
@ -236,7 +236,7 @@ public:
}
void RemovePeer(const broker::endpoint_id& peer) {
std::lock_guard<std::mutex> lock(mutex);
std::scoped_lock<std::mutex> lock(mutex);
if ( auto it = stats_map.find(peer); it != stats_map.end() )
it->second.is_zombie = true;
}
@ -271,7 +271,7 @@ public:
std::list<broker::event_ptr> tmp;
tmp.emplace_back(std::move(event));
{
std::lock_guard<std::mutex> lock(mutex_);
std::scoped_lock<std::mutex> lock(mutex_);
queue_.splice(queue_.end(), tmp);
if ( queue_.size() == 1 ) {
flare_.Fire();
@ -281,7 +281,7 @@ public:
auto Drain() {
std::list<broker::event_ptr> events;
std::lock_guard<std::mutex> lock(mutex_);
std::scoped_lock<std::mutex> lock(mutex_);
if ( ! queue_.empty() ) {
queue_.swap(events);
flare_.Extinguish();
@ -812,12 +812,10 @@ void Manager::Unpeer(const string& addr, uint16_t port) {
}
bool Manager::IsOutboundPeering(const string& addr, uint16_t port) const {
return bstate->outbound_peerings.find(broker::network_info(addr, port)) != bstate->outbound_peerings.end();
return bstate->outbound_peerings.contains(broker::network_info(addr, port));
}
bool Manager::IsOutboundPeering(const broker::network_info& ni) const {
return bstate->outbound_peerings.find(ni) != bstate->outbound_peerings.end();
}
bool Manager::IsOutboundPeering(const broker::network_info& ni) const { return bstate->outbound_peerings.contains(ni); }
std::vector<broker::peer_info> Manager::Peers() const {
if ( bstate->endpoint.is_shutdown() )
@ -2110,7 +2108,7 @@ const Stats& Manager::GetStatistics() {
TableValPtr Manager::GetPeeringStatsTable() { return bstate->peerBufferState->GetPeeringStatsTable(); }
bool Manager::AddForwardedStore(const std::string& name, TableValPtr table) {
if ( forwarded_stores.find(name) != forwarded_stores.end() ) {
if ( forwarded_stores.contains(name) ) {
reporter->Error("same &broker_store %s specified for two different variables", name.c_str());
return false;
}
@ -2127,7 +2125,7 @@ void Manager::PrepareForwarding(const std::string& name) {
if ( ! handle )
return;
if ( forwarded_stores.find(name) == forwarded_stores.end() )
if ( ! forwarded_stores.contains(name) )
return;
handle->forward_to = forwarded_stores.at(name);

View file

@ -87,7 +87,7 @@ function Broker::__set_contains%(s: Broker::Data, key: any%): bool
return zeek::val_mgr->False();
}
return zeek::val_mgr->Bool(v.find(*k) != v.end());
return zeek::val_mgr->Bool(v.contains(*k));
%}
function Broker::__set_insert%(s: Broker::Data, key: any%): bool
@ -191,7 +191,7 @@ function Broker::__table_contains%(t: Broker::Data, key: any%): bool
return zeek::val_mgr->False();
}
return zeek::val_mgr->Bool(v.find(*k) != v.end());
return zeek::val_mgr->Bool(v.contains(*k));
%}
function Broker::__table_insert%(t: Broker::Data, key: any, val: any%): Broker::Data

View file

@ -46,7 +46,7 @@ std::unique_ptr<LogSerializer> Manager::InstantiateLogSerializer(const zeek::Enu
bool Manager::ListenWebSocket(const websocket::detail::ServerOptions& options) {
WebSocketServerKey key{options.host, options.port};
if ( websocket_servers.count(key) != 0 ) {
if ( websocket_servers.contains(key) ) {
const auto& entry = websocket_servers[key];
if ( entry.options == options )
return true;

View file

@ -736,7 +736,7 @@ bool ZeroMQBackend::DoProcessBackendMessage(int tag, byte_buffer_span payload) {
if ( tag == 1 ) {
// If this is the first time the subscription was observed, raise
// the ZeroMQ internal event.
if ( xpub_subscriptions.count(topic) == 0 ) {
if ( ! xpub_subscriptions.contains(topic) ) {
eh = event_subscription;
xpub_subscriptions.insert(topic);
}

View file

@ -175,7 +175,7 @@ void WebSocketClient::SetSubscriptions(const std::vector<std::string>& topic_pre
}
void WebSocketClient::SetSubscriptionActive(const std::string& topic_prefix) {
if ( subscriptions_state.count(topic_prefix) == 0 ) {
if ( ! subscriptions_state.contains(topic_prefix) ) {
zeek::reporter->InternalWarning("Unknown topic_prefix for WebSocket client %s!", topic_prefix.c_str());
return;
}

View file

@ -373,7 +373,7 @@ bool Manager::RemoveFile(const string& file_id) {
return true;
}
bool Manager::IsIgnored(const string& file_id) { return ignored.find(file_id) != ignored.end(); }
bool Manager::IsIgnored(const string& file_id) { return ignored.contains(file_id); }
string Manager::GetFileID(const zeek::Tag& tag, Connection* c, bool is_orig) {
current_file_id.clear();

View file

@ -246,7 +246,7 @@ RecordValPtr X509::ParseCertificate(X509Val* cert_val, file_analysis::File* f) {
X509_STORE* X509::GetRootStore(TableVal* root_certs) {
// If this certificate store was built previously, just reuse the old one.
if ( x509_stores.count(root_certs) > 0 )
if ( x509_stores.contains(root_certs) )
return x509_stores[root_certs];
X509_STORE* ctx = X509_STORE_new();

View file

@ -247,13 +247,13 @@ bool Manager::RegisterFd(int fd, IOSource* src, int flags) {
std::vector<struct kevent> new_events;
if ( (flags & IOSource::READ) != 0 ) {
if ( fd_map.count(fd) == 0 ) {
if ( ! fd_map.contains(fd) ) {
new_events.push_back({});
EV_SET(&(new_events.back()), fd, EVFILT_READ, EV_ADD, 0, 0, nullptr);
}
}
if ( (flags & IOSource::WRITE) != 0 ) {
if ( write_fd_map.count(fd) == 0 ) {
if ( ! write_fd_map.contains(fd) ) {
new_events.push_back({});
EV_SET(&(new_events.back()), fd, EVFILT_WRITE, EV_ADD, 0, 0, nullptr);
}
@ -287,13 +287,13 @@ bool Manager::UnregisterFd(int fd, IOSource* src, int flags) {
std::vector<struct kevent> new_events;
if ( (flags & IOSource::READ) != 0 ) {
if ( fd_map.count(fd) != 0 ) {
if ( fd_map.contains(fd) ) {
new_events.push_back({});
EV_SET(&(new_events.back()), fd, EVFILT_READ, EV_DELETE, 0, 0, nullptr);
}
}
if ( (flags & IOSource::WRITE) != 0 ) {
if ( write_fd_map.count(fd) != 0 ) {
if ( write_fd_map.contains(fd) ) {
new_events.push_back({});
EV_SET(&(new_events.back()), fd, EVFILT_WRITE, EV_DELETE, 0, 0, nullptr);
}

View file

@ -1317,7 +1317,7 @@ bool Manager::DelayFinish(const EnumValPtr& id, const RecordValPtr& record, cons
// Delaying has completed.
bool Manager::DelayCompleted(Stream* stream, detail::DelayInfo& delay_info) {
auto token = detail::to_internal_delay_token(delay_info.TokenVal());
assert(stream->delay_tokens.find(token) != stream->delay_tokens.end());
assert(stream->delay_tokens.contains(token));
DBG_LOG(DBG_LOGGING, "DelayCompleted() for log record %p RefCnt=%d token=%" PRIu64, delay_info.Record().get(),
delay_info.Record()->RefCnt(), token);

View file

@ -155,7 +155,7 @@ bool IPBasedAnalyzer::IsLikelyServerPort(uint32_t port) const {
// We exploit our knowledge of PortVal's internal storage mechanism here.
port |= server_port_mask;
return port_cache.find(port) != port_cache.end();
return port_cache.contains(port);
}
zeek::Connection* IPBasedAnalyzer::NewConn(IPBasedConnKeyPtr key, const Packet* pkt) {

View file

@ -173,14 +173,14 @@ public:
*
* @param tag The component tag to check.
*/
auto HasComponentMapping(const zeek::Tag& tag) const { return component_mapping_by_src.count(tag); }
bool HasComponentMapping(const zeek::Tag& tag) const { return component_mapping_by_src.contains(tag); }
/**
* Returns true if a given component is mapped to from a different one.
*
* @param tag The component tag to check.
*/
bool ProvidesComponentMapping(const zeek::Tag& tag) const { return component_mapping_by_dst.count(tag); }
bool ProvidesComponentMapping(const zeek::Tag& tag) const { return component_mapping_by_dst.contains(tag); }
private:
/** Script layer module in which component tags live. */

View file

@ -81,7 +81,7 @@ void Manager::SearchDynamicPlugins(const std::string& dir) {
std::string canon_path = canon.string();
if ( searched_dirs.count(canon_path) )
if ( searched_dirs.contains(canon_path) )
return;
searched_dirs.emplace(canon_path);

View file

@ -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"

View file

@ -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

View file

@ -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);

View file

@ -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];

View file

@ -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;
}

View file

@ -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;

View file

@ -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;
}

View file

@ -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;
}

View file

@ -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);

View file

@ -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));
}

View file

@ -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];
}

View file

@ -26,7 +26,7 @@ public:
TraversalCode PostExpr(const Expr*) override;
TraversalCode PreType(const Type* t) override {
if ( types_seen.count(t) > 0 )
if ( types_seen.contains(t) )
return TC_ABORTSTMT;
types_seen.insert(t);
return TC_CONTINUE;

View file

@ -1186,7 +1186,7 @@ bool CmpExpr::IsHasElementsTest() const {
static std::set<ExprTag> rel_tags = {EXPR_EQ, EXPR_NE, EXPR_LT, EXPR_LE, EXPR_GE, EXPR_GT};
auto t = Tag(); // note, we may invert t below
if ( rel_tags.count(t) == 0 )
if ( ! rel_tags.contains(t) )
return false;
auto op1 = GetOp1();
@ -2396,7 +2396,7 @@ bool LambdaExpr::IsReduced(Reducer* c) const {
for ( auto& cp : *captures ) {
auto& cid = cp.Id();
if ( private_captures.count(cid.get()) == 0 && ! c->ID_IsReduced(cid) )
if ( ! private_captures.contains(cid.get()) && ! c->ID_IsReduced(cid) )
return NonReduced(this);
}
@ -2424,7 +2424,7 @@ void LambdaExpr::UpdateCaptures(Reducer* c) {
for ( auto& cp : *captures ) {
auto& cid = cp.Id();
if ( private_captures.count(cid.get()) == 0 )
if ( ! private_captures.contains(cid.get()) )
cp.SetID(c->UpdateID(cid));
}
@ -2955,7 +2955,7 @@ RecordFieldUpdatesExpr::RecordFieldUpdatesExpr(ExprTag t, const std::vector<cons
// Consistency check that the statement is indeed in the pool,
// before we remove it.
ASSERT(stmt_pool.count(s) > 0);
ASSERT(stmt_pool.contains(s));
stmt_pool.erase(s);
}

View file

@ -216,7 +216,7 @@ void IDOptInfo::BranchBeyond(const Stmt* end_s, const Stmt* block, bool close_al
printf("ID %s branching forward from %d beyond %d: %s\n", trace_ID, end_s->GetOptInfo()->stmt_num,
block->GetOptInfo()->stmt_num, obj_desc(end_s).c_str());
ASSERT(pending_confluences.count(block) > 0);
ASSERT(pending_confluences.contains(block));
auto ar = ActiveRegionIndex();
if ( ar != NO_DEF )
@ -332,12 +332,12 @@ void IDOptInfo::ConfluenceBlockEndsAfter(const Stmt* s, bool no_orig_flow) {
if ( ur.EndsAfter() == NO_DEF ) { // End this region.
ur.SetEndsAfter(stmt_num);
if ( ur.StartsAfter() <= cs_stmt_num && no_orig_flow && pc.count(i) == 0 )
if ( ur.StartsAfter() <= cs_stmt_num && no_orig_flow && ! pc.contains(i) )
// Don't include this region in our assessment.
continue;
}
else if ( ur.EndsAfter() < cs_stmt_num || pc.count(i) == 0 )
else if ( ur.EndsAfter() < cs_stmt_num || ! pc.contains(i) )
// Irrelevant, didn't extend into confluence region.
// We test here just to avoid the set lookup in
// the next test, which presumably will sometimes

View file

@ -116,7 +116,7 @@ void Inliner::Analyze() {
for ( auto& ccc : call_set[cc] ) {
// For each of those, if we don't
// already have it, add it.
if ( c.second.count(ccc) > 0 )
if ( c.second.contains(ccc) )
// We already have it.
continue;
@ -157,7 +157,7 @@ void Inliner::Analyze() {
if ( func->Flavor() != FUNC_FLAVOR_FUNCTION )
continue;
if ( non_recursive_funcs.count(func) == 0 )
if ( ! non_recursive_funcs.contains(func) )
continue;
if ( ! is_ZAM_compilable(f.Profile()) )
@ -202,7 +202,7 @@ void Inliner::CoalesceEventHandlers() {
if ( func->GetKind() == Func::SCRIPT_FUNC && func->GetBodies().size() > 1 ) {
++event_handlers[func];
ASSERT(body_to_info.count(body.get()) == 0);
ASSERT(! body_to_info.contains(body.get()));
body_to_info[body.get()] = i;
}
}
@ -420,7 +420,7 @@ ExprPtr Inliner::DoInline(ScriptFuncPtr sf, StmtPtr body, ListExprPtr args, Scop
for ( int i = 0; i < nparam; ++i ) {
auto& vi = vars[i];
params.emplace_back(vi);
param_is_modified.emplace_back((pf->Assignees().count(vi.get()) > 0));
param_is_modified.emplace_back((pf->Assignees().contains(vi.get())));
}
// Recursively inline the body. This is safe to do because we've

View file

@ -30,7 +30,7 @@ public:
ExprPtr CheckForInlining(CallExprPtr c);
// True if every instance of the function was inlined.
bool WasFullyInlined(const Func* f) { return did_inline.count(f) > 0 && skipped_inlining.count(f) == 0; }
bool WasFullyInlined(const Func* f) { return did_inline.contains(f) && ! skipped_inlining.contains(f); }
protected:
// Driver routine that analyzes all of the script functions and

View file

@ -41,7 +41,7 @@ private:
class ObjMgr {
public:
void AddObj(const Obj* o) {
if ( obj_collection.count(o) == 0 )
if ( ! obj_collection.contains(o) )
obj_collection.emplace(std::pair<const Obj*, ObjWrapper>{o, ObjWrapper(o)});
}

View file

@ -52,7 +52,7 @@ ProfileFunc::ProfileFunc(const Func* func, const StmtPtr& body, bool _abs_rec_fi
num_params = profiled_func_t->Params()->NumFields();
for ( auto l : locals ) {
if ( captures.count(l) == 0 && l->Offset() < num_params )
if ( ! captures.contains(l) && l->Offset() < num_params )
params.insert(l);
}
}
@ -470,7 +470,7 @@ TraversalCode ProfileFunc::PreExpr(const Expr* e) {
// types if needed.
auto res_type = e->GetType().get();
auto orig_type = e->GetOp1()->GetType().get();
if ( type_aliases.count(res_type) == 0 )
if ( ! type_aliases.contains(res_type) )
type_aliases[orig_type] = {res_type};
else
type_aliases[orig_type].insert(res_type);
@ -541,12 +541,12 @@ void ProfileFunc::TrackID(const ID* id) {
}
void ProfileFunc::TrackAssignment(const ID* id) {
if ( assignees.count(id) > 0 )
if ( assignees.contains(id) )
++assignees[id];
else
assignees[id] = 1;
if ( id->IsGlobal() || captures.count(id) > 0 )
if ( id->IsGlobal() || captures.contains(id) )
non_local_assignees.insert(id);
}
@ -562,7 +562,7 @@ void ProfileFunc::CheckRecordConstructor(TypePtr t) {
auto attrs = td->attrs.get();
constructor_attrs[attrs] = rt;
if ( rec_constructor_attrs.count(rt.get()) == 0 )
if ( ! rec_constructor_attrs.contains(rt.get()) )
rec_constructor_attrs[rt.get()] = {attrs};
else
rec_constructor_attrs[rt.get()].insert(attrs);
@ -735,7 +735,7 @@ void ProfileFuncs::MergeInProfile(ProfileFunc* pf) {
AnalyzeAttrs(a.first, a.second.get());
for ( auto& ta : pf->TypeAliases() ) {
if ( type_aliases.count(ta.first) == 0 )
if ( ! type_aliases.contains(ta.first) )
type_aliases[ta.first] = std::set<const Type*>{};
type_aliases[ta.first].insert(ta.second.begin(), ta.second.end());
}
@ -1294,7 +1294,7 @@ bool ProfileFuncs::AssessSideEffects(const ExprPtr& e, IDSet& non_local_ids, Typ
// in an attribute context indicates an implicit call.
return GetCallSideEffects(e->AsNameExpr(), non_local_ids, aggrs, is_unknown);
ASSERT(expr_profs.count(e.get()) != 0);
ASSERT(expr_profs.contains(e.get()));
auto pf = expr_profs[e.get()];
return AssessSideEffects(pf.get(), non_local_ids, aggrs, is_unknown);
}
@ -1342,7 +1342,7 @@ bool ProfileFuncs::AssessSideEffects(const ProfileFunc* pf, IDSet& non_local_ids
}
auto pff = func_profs[f];
if ( active_func_profiles.count(pff) > 0 )
if ( active_func_profiles.contains(pff) )
// We're already processing this function and arrived here via
// recursion. Skip further analysis here, we'll do it instead
// for the original instance.
@ -1415,7 +1415,7 @@ bool ProfileFuncs::AssessSideEffects(const SideEffectsOp* se, SideEffectsOp::Acc
}
std::shared_ptr<SideEffectsOp> ProfileFuncs::GetCallSideEffects(const ScriptFunc* sf) {
if ( lambda_primaries.count(sf->GetName()) > 0 )
if ( lambda_primaries.contains(sf->GetName()) )
sf = lambda_primaries[sf->GetName()];
auto sf_se = func_side_effects.find(sf);
@ -1427,7 +1427,7 @@ std::shared_ptr<SideEffectsOp> ProfileFuncs::GetCallSideEffects(const ScriptFunc
IDSet nla;
TypeSet mod_aggrs;
ASSERT(func_profs.count(sf) != 0);
ASSERT(func_profs.contains(sf));
auto pf = func_profs[sf];
if ( ! AssessSideEffects(pf.get(), nla, mod_aggrs, is_unknown) )
// Can't figure it out yet.
@ -1450,7 +1450,7 @@ static std::unordered_map<std::string, std::string> filename_module;
void switch_to_module(const char* module_name) {
auto loc = GetCurrentLocation();
if ( loc.FirstLine() != 0 && filename_module.count(loc.FileName()) == 0 )
if ( loc.FirstLine() != 0 && ! filename_module.contains(loc.FileName()) )
filename_module[loc.FileName()] = module_name;
}
@ -1542,7 +1542,7 @@ ASTBlockAnalyzer::ASTBlockAnalyzer(std::vector<FuncInfo>& funcs) {
static bool is_compound_stmt(const Stmt* s) {
static std::set<StmtTag> compound_stmts = {STMT_FOR, STMT_IF, STMT_LIST, STMT_SWITCH, STMT_WHEN, STMT_WHILE};
return compound_stmts.count(s->Tag()) > 0;
return compound_stmts.contains(s->Tag());
}
TraversalCode ASTBlockAnalyzer::PreStmt(const Stmt* s) {
@ -1580,7 +1580,7 @@ std::string ASTBlockAnalyzer::BuildExpandedDescription(const Location* loc) {
}
auto lk = LocKey(loc);
if ( exp_desc.count(lk) == 0 )
if ( ! exp_desc.contains(lk) )
exp_desc[lk] = ls;
return ls;

View file

@ -674,7 +674,7 @@ public:
// should always be true other than for certain functions with empty
// bodies that are created post-parsing. Available for debugging so
// we can assert we have these.
bool HaveExpDesc(const Location* loc) const { return exp_desc.count(LocKey(loc)) > 0; }
bool HaveExpDesc(const Location* loc) const { return exp_desc.contains(LocKey(loc)); }
private:
// Construct the full expanded description associated with the given

View file

@ -327,7 +327,7 @@ bool Reducer::ID_IsReducedOrTopLevel(const ID* id) {
}
bool Reducer::ID_IsReduced(const ID* id) const {
return inline_block_level == 0 || tracked_ids.count(id) > 0 || id->IsGlobal() || IsTemporary(id);
return inline_block_level == 0 || tracked_ids.contains(id) || id->IsGlobal() || IsTemporary(id);
}
StmtPtr Reducer::GenParam(const IDPtr& id, ExprPtr rhs, bool is_modified) {
@ -335,7 +335,7 @@ StmtPtr Reducer::GenParam(const IDPtr& id, ExprPtr rhs, bool is_modified) {
param->SetLocationInfo(rhs->GetLocationInfo());
auto rhs_id = rhs->Tag() == EXPR_NAME ? rhs->AsNameExpr()->IdPtr() : nullptr;
if ( rhs_id && pf->Locals().count(rhs_id.get()) == 0 && ! rhs_id->IsConst() )
if ( rhs_id && ! pf->Locals().contains(rhs_id.get()) && ! rhs_id->IsConst() )
// It's hard to guarantee the RHS won't change during
// the inline block's execution.
is_modified = true;
@ -838,14 +838,14 @@ IDPtr Reducer::GenLocal(const IDPtr& orig) {
local_id->GetOptInfo()->SetTemp();
IDPtr prev;
if ( orig_to_new_locals.count(orig.get()) )
if ( orig_to_new_locals.contains(orig.get()) )
prev = orig_to_new_locals[orig.get()];
AddNewLocal(local_id);
om.AddObj(orig.get());
orig_to_new_locals[orig.get()] = local_id;
if ( ! block_locals.empty() && ret_vars.count(orig.get()) == 0 )
if ( ! block_locals.empty() && ! ret_vars.contains(orig.get()) )
block_locals.back()[orig.get()] = prev;
return local_id;
@ -853,7 +853,7 @@ IDPtr Reducer::GenLocal(const IDPtr& orig) {
bool Reducer::IsNewLocal(const ID* id) const {
ID* non_const_ID = (ID*)id; // I don't get why C++ requires this
return new_locals.count(non_const_ID) != 0;
return new_locals.contains(non_const_ID);
}
std::shared_ptr<TempVar> Reducer::FindTemporary(const ID* id) const {

View file

@ -83,9 +83,9 @@ public:
bool IsNewLocal(const ID* id) const;
bool IsTemporary(const ID* id) const { return FindTemporary(id) != nullptr; }
bool IsParamTemp(const ID* id) const { return param_temps.count(id) > 0; }
bool IsParamTemp(const ID* id) const { return param_temps.contains(id); }
bool IsConstantVar(const ID* id) const { return constant_vars.find(id) != constant_vars.end(); }
bool IsConstantVar(const ID* id) const { return constant_vars.contains(id); }
// True if the Reducer is being used in the context of a second
// pass over for AST optimization.
@ -97,7 +97,7 @@ public:
// A predicate that returns true if the given statement should
// be removed due to AST optimization.
bool ShouldOmitStmt(const Stmt* s) const { return omitted_stmts.find(s) != omitted_stmts.end(); }
bool ShouldOmitStmt(const Stmt* s) const { return omitted_stmts.contains(s); }
// Provides a replacement for the given statement due to
// AST optimization, or nil if there's no replacement.

View file

@ -52,9 +52,9 @@ void analyze_lambda(LambdaExpr* l) {
void analyze_when_lambda(LambdaExpr* l) { when_lambdas.insert(l->PrimaryFunc().get()); }
bool is_lambda(const ScriptFunc* f) { return lambdas.count(f) > 0; }
bool is_lambda(const ScriptFunc* f) { return lambdas.contains(f); }
bool is_when_lambda(const ScriptFunc* f) { return when_lambdas.count(f) > 0; }
bool is_when_lambda(const ScriptFunc* f) { return when_lambdas.contains(f); }
void analyze_global_stmts(Stmt* stmts) {
if ( analysis_options.gen_standalone_CPP && obj_matches_opt_files(stmts) )
@ -396,7 +396,7 @@ static void report_CPP() {
}
auto hash = f.Profile()->HashVal();
bool have = compiled_scripts.count(hash) > 0;
bool have = compiled_scripts.contains(hash);
printf("script function %s (hash %llu): %s\n", name.c_str(), hash, have ? "yes" : "no");
@ -408,7 +408,7 @@ static void report_CPP() {
int addl = 0;
for ( const auto& s : compiled_scripts )
if ( already_reported.count(s.first) == 0 ) {
if ( ! already_reported.contains(s.first) ) {
printf("%s body (hash %llu)\n", s.second.body->Name().c_str(), s.first);
++addl;
}
@ -441,7 +441,7 @@ static void use_CPP() {
// we're using code compiled for standalone.
if ( f.Body()->Tag() != STMT_CPP ) {
auto func = f.Func();
if ( added_bodies[func->GetName()].count(hash) > 0 )
if ( added_bodies[func->GetName()].contains(hash) )
// We've already added the
// replacement. Delete orig.
func->ReplaceBody(f.Body(), nullptr);
@ -535,7 +535,7 @@ static void analyze_scripts_for_ZAM(std::shared_ptr<ProfileFuncs> pfs) {
bool is_lambda = l != lambdas.end();
if ( ! analysis_options.compile_all && ! is_lambda && inl && inl->WasFullyInlined(func.get()) &&
func_used_indirectly.count(func.get()) == 0 ) {
! func_used_indirectly.contains(func.get()) ) {
// No need to compile as it won't be called directly. We'd
// like to zero out the body to recover the memory, but a *few*
// such functions do get called, such as by the event engine
@ -732,7 +732,7 @@ bool has_AST_node_unknown_to_script_opt(const ProfileFunc* prof, bool /* is_ZAM
static_assert(NUM_STMTS == SCRIPT_OPT_NUM_STMTS);
for ( auto& s : prof->Stmts() )
if ( known_stmts.count(s->Tag()) == 0 )
if ( ! known_stmts.contains(s->Tag()) )
return true;
// clang-format off
@ -821,7 +821,7 @@ bool has_AST_node_unknown_to_script_opt(const ProfileFunc* prof, bool /* is_ZAM
static_assert(NUM_EXPRS == SCRIPT_OPT_NUM_EXPRS);
for ( auto& e : prof->Exprs() )
if ( known_exprs.count(e->Tag()) == 0 )
if ( ! known_exprs.contains(e->Tag()) )
return true;
return false;

View file

@ -771,7 +771,7 @@ static unsigned int find_rec_assignment_chain(const std::vector<StmtPtr>& stmts,
return i;
auto lhs_field = lhs->AsFieldExpr()->Field();
if ( fields_seen.count(lhs_field) > 0 )
if ( fields_seen.contains(lhs_field) )
// Earlier in this chain we've already seen "x$a", so end the
// chain at this repeated use because it's no longer a simple
// block of field assignments.
@ -925,7 +925,7 @@ static bool simplify_chain(const std::vector<StmtPtr>& stmts, unsigned int start
// At this point, chain_stmts has only the remainders that weren't removed.
for ( auto s : stmts )
if ( chain_stmts.count(s.get()) > 0 )
if ( chain_stmts.contains(s.get()) )
f_stmts.push_back(std::move(s));
return true;
@ -1106,7 +1106,7 @@ bool WhenInfo::HasUnreducedIDs(Reducer* c) const {
for ( auto& cp : *cl ) {
const auto& cid = cp.Id();
if ( when_new_locals.count(cid.get()) == 0 && ! c->ID_IsReduced(cp.Id()) )
if ( ! when_new_locals.contains(cid.get()) && ! c->ID_IsReduced(cp.Id()) )
return true;
}
@ -1120,7 +1120,7 @@ bool WhenInfo::HasUnreducedIDs(Reducer* c) const {
void WhenInfo::UpdateIDs(Reducer* c) {
for ( auto& cp : *cl ) {
auto& cid = cp.Id();
if ( when_new_locals.count(cid.get()) == 0 )
if ( ! when_new_locals.contains(cid.get()) )
cp.SetID(c->UpdateID(cid));
}

View file

@ -49,7 +49,7 @@ UsageAnalyzer::UsageAnalyzer(std::vector<FuncInfo>& funcs) {
if ( t->AsFuncType()->Flavor() == FUNC_FLAVOR_FUNCTION )
continue;
if ( reachables.count(id) > 0 )
if ( reachables.contains(id) )
continue;
auto flavor = t->AsFuncType()->FlavorString();
@ -69,7 +69,7 @@ UsageAnalyzer::UsageAnalyzer(std::vector<FuncInfo>& funcs) {
for ( auto& gpair : globals ) {
auto& id = gpair.second;
if ( reachables.count(id.get()) > 0 )
if ( reachables.contains(id.get()) )
continue;
auto f = GetFuncIfAny(id);
@ -109,7 +109,7 @@ public:
}
TraversalCode PreType(const Type* t) override {
if ( analyzed_types.count(t) > 0 )
if ( analyzed_types.contains(t) )
return TC_ABORTSTMT;
analyzed_types.insert(t);
@ -117,7 +117,7 @@ public:
}
TraversalCode PreID(const ID* id) override {
if ( ids.count(id) > 0 )
if ( ids.contains(id) )
return TC_ABORTSTMT;
if ( attr_depth > 0 )
@ -149,7 +149,7 @@ void UsageAnalyzer::FindSeeds(IDSet& seeds) const {
auto f = GetFuncIfAny(id);
if ( f && id->GetType<FuncType>()->Flavor() == FUNC_FLAVOR_EVENT ) {
if ( script_events.count(f->GetName()) == 0 )
if ( ! script_events.contains(f->GetName()) )
seeds.insert(id.get());
continue;
@ -225,7 +225,7 @@ void UsageAnalyzer::Expand(const ID* id) {
}
TraversalCode UsageAnalyzer::PreID(const ID* id) {
if ( analyzed_IDs.count(id) > 0 )
if ( analyzed_IDs.contains(id) )
// No need to repeat the analysis.
return TC_ABORTSTMT;
@ -234,7 +234,7 @@ TraversalCode UsageAnalyzer::PreID(const ID* id) {
auto f = GetFuncIfAny(id);
if ( f && reachables.count(id) == 0 )
if ( f && ! reachables.contains(id) )
// Haven't seen this function before.
new_reachables.insert(id);
@ -254,7 +254,7 @@ TraversalCode UsageAnalyzer::PreID(const ID* id) {
}
TraversalCode UsageAnalyzer::PreType(const Type* t) {
if ( analyzed_types.count(t) > 0 )
if ( analyzed_types.contains(t) )
return TC_ABORTSTMT;
// Save processing by avoiding a re-traversal of this type.

View file

@ -49,7 +49,7 @@ void UseDefs::Dump() {
for ( int i = stmts.size(); --i >= 0; ) {
const auto& s = stmts[i];
auto uds = FindUsage(s);
auto are_copies = (UDs_are_copies.find(s) != UDs_are_copies.end());
auto are_copies = (UDs_are_copies.contains(s));
printf("UDs (%s) for %s:\n", are_copies ? "copy" : "orig", obj_desc(s).c_str());
@ -186,7 +186,7 @@ UDs UseDefs::PropagateUDs(const Stmt* s, UDs succ_UDs, const Stmt* succ_stmt, bo
if ( i == int(stmts.size()) - 1 ) { // Very last statement.
succ = succ_stmt;
if ( successor2.find(s) != successor2.end() ) {
if ( successor2.contains(s) ) {
om.AddObj(s_i);
successor2[s_i] = successor2[s];
}
@ -620,7 +620,7 @@ void UseDefs::FoldInUDs(UDs& main_UDs, const UDs& u1, const UDs& u2) {
void UseDefs::UpdateUDs(const Stmt* s, const UDs& uds) {
auto curr_uds = FindUsage(s);
if ( ! curr_uds || UDs_are_copies.find(s) != UDs_are_copies.end() ) {
if ( ! curr_uds || UDs_are_copies.contains(s) ) {
// Copy-on-write.
auto new_uds = std::make_shared<UseDefSet>();

View file

@ -27,7 +27,7 @@ public:
void Replicate(const UDs& from) { use_defs = from->use_defs; }
bool HasID(const ID* id) { return use_defs.find(id) != use_defs.end(); }
bool HasID(const ID* id) { return use_defs.contains(id); }
void Add(const ID* id) { use_defs.insert(id); }
void Remove(const ID* id) { use_defs.erase(id); }
@ -56,8 +56,8 @@ public:
void Analyze();
// True if we've computed use-defs for the given statement.
bool HasUsage(const Stmt* s) const { return use_defs_map.find(s) != use_defs_map.end(); }
bool HasUsage(const StmtPtr& s) const { return HasUsage(s.get()); }
bool HasUsage(const Stmt* s) const { return use_defs_map.contains(s); }
// Returns the use-defs for the given statement.
UDs GetUsage(const Stmt* s) const { return FindUsage(s); }

View file

@ -43,10 +43,10 @@ void finalize_functions(const std::vector<FuncInfo>& funcs) {
for ( auto& f : funcs ) {
auto func = f.Func();
if ( leave_alone.count(func) > 0 )
if ( leave_alone.contains(func) )
continue;
if ( remapped_intrp_frame_sizes.count(func) == 0 )
if ( ! remapped_intrp_frame_sizes.contains(func) )
// No entry for this function, keep current frame size.
continue;
@ -282,7 +282,7 @@ bool ZAMCompiler::PruneUnused() {
continue;
int slot = inst->v1;
if ( denizen_ending.count(slot) > 0 )
if ( denizen_ending.contains(slot) )
// Variable is used, keep assignment.
continue;
@ -306,7 +306,7 @@ bool ZAMCompiler::PruneUnused() {
// can't remove the instruction entirely because it has
// side effects. Transform the instruction into its flavor
// that doesn't make an assignment.
if ( assignmentless_op.count(inst->op) == 0 )
if ( ! assignmentless_op.contains(inst->op) )
reporter->InternalError("inconsistency in re-flavoring instruction with side effects");
inst->op_type = assignmentless_op_class[inst->op];
@ -506,14 +506,14 @@ void ZAMCompiler::ReMapFrame() {
for ( zeek_uint_t i = 0; i < insts1.size(); ++i ) {
auto inst = insts1[i];
if ( inst_beginnings.count(inst) == 0 )
if ( ! inst_beginnings.contains(inst) )
continue;
auto vars = inst_beginnings[inst];
for ( auto v : vars ) {
// Don't remap variables whose values aren't actually used.
int slot = frame_layout1[v];
if ( denizen_ending.count(slot) > 0 )
if ( denizen_ending.contains(slot) )
ReMapVar(v, slot, i);
}
}
@ -667,7 +667,7 @@ void ZAMCompiler::ReMapInterpreterFrame() {
// Update frame sizes for functions that might have more than
// one body.
auto f = func.get();
if ( remapped_intrp_frame_sizes.count(f) == 0 || remapped_intrp_frame_sizes[f] < next_interp_slot )
if ( ! remapped_intrp_frame_sizes.contains(f) || remapped_intrp_frame_sizes[f] < next_interp_slot )
remapped_intrp_frame_sizes[f] = next_interp_slot;
}
@ -753,7 +753,7 @@ void ZAMCompiler::CheckSlotAssignment(int slot, const ZInstI* inst) {
}
void ZAMCompiler::SetLifetimeStart(int slot, const ZInstI* inst) {
if ( denizen_beginning.count(slot) > 0 ) {
if ( denizen_beginning.contains(slot) ) {
// Beginning of denizen's lifetime already seen, nothing
// more to do other than check for consistency.
ASSERT(denizen_beginning[slot]->inst_num <= inst->inst_num);
@ -762,7 +762,7 @@ void ZAMCompiler::SetLifetimeStart(int slot, const ZInstI* inst) {
else { // denizen begins here
denizen_beginning[slot] = inst;
if ( inst_beginnings.count(inst) == 0 )
if ( ! inst_beginnings.contains(inst) )
// Need to create a set to track the denizens
// beginning at the instruction.
inst_beginnings[inst] = {};
@ -777,7 +777,7 @@ void ZAMCompiler::CheckSlotUse(int slot, const ZInstI* inst) {
ASSERT(static_cast<zeek_uint_t>(slot) < frame_denizens.size());
if ( denizen_beginning.count(slot) == 0 ) {
if ( ! denizen_beginning.contains(slot) ) {
ODesc d;
inst->loc->Loc()->Describe(&d);
reporter->Error("%s: value used but not set: %s", d.Description(), frame_denizens[slot]->Name());
@ -788,7 +788,7 @@ void ZAMCompiler::CheckSlotUse(int slot, const ZInstI* inst) {
// at a lower loop depth than that for this instruction, then we
// extend its lifetime to the end of this instruction's loop.
if ( reducer->IsTemporary(frame_denizens[slot]) ) {
ASSERT(denizen_beginning.count(slot) > 0);
ASSERT(denizen_beginning.contains(slot));
int definition_depth = denizen_beginning[slot]->loop_depth;
if ( inst->loop_depth > definition_depth )
@ -805,7 +805,7 @@ void ZAMCompiler::ExtendLifetime(int slot, const ZInstI* inst) {
auto id = frame_denizens[slot];
auto& t = id->GetType();
if ( denizen_ending.count(slot) > 0 ) {
if ( denizen_ending.contains(slot) ) {
// End of denizen's lifetime already seen. Check for
// consistency and then extend as needed.
@ -828,7 +828,7 @@ void ZAMCompiler::ExtendLifetime(int slot, const ZInstI* inst) {
if ( old_inst->inst_num < inst->inst_num ) { // Extend.
inst_endings[old_inst].erase(frame_denizens[slot]);
if ( inst_endings.count(inst) == 0 )
if ( ! inst_endings.contains(inst) )
inst_endings[inst] = {};
inst_endings[inst].insert(frame_denizens[slot]);
@ -839,7 +839,7 @@ void ZAMCompiler::ExtendLifetime(int slot, const ZInstI* inst) {
else { // first time seeing a use of this denizen
denizen_ending[slot] = inst;
if ( inst_endings.count(inst) == 0 ) {
if ( ! inst_endings.contains(inst) ) {
IDSet denizens;
inst_endings[inst] = denizens;
}
@ -988,9 +988,9 @@ void ZAMCompiler::KillInst(zeek_uint_t i) {
if ( inst->aux && ! inst->aux->cft.empty() ) {
auto& cft = inst->aux->cft;
if ( cft.count(CFT_ELSE) > 0 ) {
if ( cft.contains(CFT_ELSE) ) {
// Push forward unless this was the end of the block.
if ( cft.count(CFT_BLOCK_END) == 0 ) {
if ( ! cft.contains(CFT_BLOCK_END) ) {
ASSERT(succ);
AddCFT(succ, CFT_ELSE);
}
@ -1007,15 +1007,15 @@ void ZAMCompiler::KillInst(zeek_uint_t i) {
// because they just lead to their following instruction, and next's
// if they become dead code. However, loops and loop conditionals
// should not be killed.
ASSERT(cft.count(CFT_LOOP) == 0);
ASSERT(cft.count(CFT_LOOP_COND) == 0);
ASSERT(! cft.contains(CFT_LOOP));
ASSERT(! cft.contains(CFT_LOOP_COND));
}
}
void ZAMCompiler::BackPropagateCFT(int inst_num, ControlFlowType cf_type) {
auto inst = insts1[inst_num];
auto& cft = inst->aux->cft;
if ( cft.count(cf_type) == 0 )
if ( ! cft.contains(cf_type) )
return;
int j = inst_num;

View file

@ -43,7 +43,7 @@ void ZAMCompiler::Init() {
TrackMemoryManagement();
non_recursive = non_recursive_funcs.count(func.get()) > 0;
non_recursive = non_recursive_funcs.contains(func.get());
}
void ZAMCompiler::InitGlobals() {
@ -92,7 +92,7 @@ void ZAMCompiler::InitLocals() {
if ( IsCapture(l) )
continue;
if ( pf->WhenLocals().count(l) > 0 )
if ( pf->WhenLocals().contains(l) )
continue;
auto non_const_l = const_cast<ID*>(l);

View file

@ -322,7 +322,7 @@ const ZAMStmt ZAMCompiler::CompileRecFieldUpdates(const RecordFieldUpdatesExpr*
bool homogeneous = field_tags.size() == 1;
// Here we leverage the fact that C++ "+=" works identically for
// signed and unsigned int's.
if ( ! homogeneous && field_tags.size() == 2 && field_tags.count(TYPE_INT) > 0 && field_tags.count(TYPE_COUNT) > 0 )
if ( ! homogeneous && field_tags.size() == 2 && field_tags.contains(TYPE_INT) && field_tags.contains(TYPE_COUNT) )
homogeneous = true;
ZOp op;
@ -338,7 +338,7 @@ const ZAMStmt ZAMCompiler::CompileRecFieldUpdates(const RecordFieldUpdatesExpr*
}
else if ( homogeneous ) {
if ( field_tags.count(TYPE_DOUBLE) > 0 )
if ( field_tags.contains(TYPE_DOUBLE) )
op = OP_REC_ADD_DOUBLE_FIELDS_VV;
else
// Here we leverage that += will work for both signed/unsigned.
@ -951,7 +951,7 @@ const ZAMStmt ZAMCompiler::BuildLambda(int n_slot, ExprPtr e) {
for ( int i = 0; i < ncaptures; ++i ) {
auto& id_i = (*captures)[i].Id();
if ( pf->WhenLocals().count(id_i.get()) > 0 )
if ( pf->WhenLocals().contains(id_i.get()) )
aux->Add(i, nullptr);
else
aux->Add(i, FrameSlot(id_i), id_i->GetType());

View file

@ -118,7 +118,7 @@ eval static auto any_val = ZVal();
macro EvalSwitchBody(index, branch, cases, postscript)
{
auto t = cases[index];
if ( t.find(v) == t.end() )
if ( ! t.contains(v) )
pc = branch;
else
pc = t[v];

View file

@ -102,7 +102,7 @@ void validate_ZAM_insts() {
for ( int i = 0; i < int(OP_NOP); ++i ) {
auto zop = ZOp(i);
if ( zam_inst_desc.find(zop) == zam_inst_desc.end() && assignment_flavor.find(zop) == assignment_flavor.end() )
if ( ! zam_inst_desc.contains(zop) && ! assignment_flavor.contains(zop) )
reporter->InternalError("op %s missing from description", ZOP_name(zop));
}

View file

@ -22,7 +22,7 @@ bool ZAMCompiler::IsUnused(const IDPtr& id, const Stmt* where) const {
bool ZAMCompiler::IsCapture(const ID* id) const {
const auto& c = pf->CapturesOffsets();
return c.find(id) != c.end();
return c.contains(id);
}
int ZAMCompiler::CaptureOffset(const ID* id) const {
@ -143,7 +143,7 @@ int ZAMCompiler::RawSlot(const ID* id) {
return id_slot->second;
}
bool ZAMCompiler::HasFrameSlot(const ID* id) const { return frame_layout1.find(id) != frame_layout1.end(); }
bool ZAMCompiler::HasFrameSlot(const ID* id) const { return frame_layout1.contains(id); }
int ZAMCompiler::NewSlot(bool is_managed) {
char buf[8192];

View file

@ -653,7 +653,7 @@ bool ZInstI::IsGlobalLoad() const {
}
}
return global_ops.count(op) > 0;
return global_ops.contains(op);
}
bool ZInstI::IsCaptureLoad() const { return op == OP_LOAD_CAPTURE_Vi || op == OP_LOAD_MANAGED_CAPTURE_Vi; }

View file

@ -83,7 +83,7 @@ ZOp AssignmentFlavor(ZOp orig, TypeTag tag, bool strict) {
default: break;
}
if ( assignment_flavor.count(orig) == 0 ) {
if ( ! assignment_flavor.contains(orig) ) {
if ( strict )
ASSERT(false);
else
@ -92,7 +92,7 @@ ZOp AssignmentFlavor(ZOp orig, TypeTag tag, bool strict) {
auto orig_map = assignment_flavor[orig];
if ( orig_map.count(tag) == 0 ) {
if ( ! orig_map.contains(tag) ) {
if ( strict )
ASSERT(false);
else

View file

@ -1251,7 +1251,7 @@ function hexdump%(data_str: string%) : string
function reverse%(str: string%) : string
%{
string s = str->ToStdString();
reverse(s.begin(), s.end());
std::ranges::reverse(s);
return zeek::make_intrusive<zeek::StringVal>(s.length(), (const char*)s.c_str());
%}
@ -1308,8 +1308,8 @@ static int64_t do_find_str(zeek::StringVal* str, zeek::StringVal* sub, int64_t s
if ( ! case_sensitive )
{
transform(s.begin(), s.end(), s.begin(), ::tolower);
transform(sb.begin(), sb.end(), sb.begin(), ::tolower);
std::ranges::transform(s, s.begin(), ::tolower);
std::ranges::transform(sb, sb.begin(), ::tolower);
}
if ( rfind )

View file

@ -1071,7 +1071,7 @@ std::optional<SupervisedNode> Stem::Poll() {
if ( cmd == "create" ) {
const auto& node_json = msg_tokens[2];
assert(nodes.find(node_name) == nodes.end());
assert(! nodes.contains(node_name));
auto node_config = Supervisor::NodeConfig::FromJSON(node_json);
auto it = nodes.emplace(node_name, std::move(node_config)).first;
auto& node = it->second;
@ -1514,7 +1514,7 @@ std::string Supervisor::Create(const Supervisor::NodeConfig& node) {
if ( node.name.find(' ') != std::string::npos )
return util::fmt("node names must not contain spaces: '%s'", node.name.data());
if ( nodes.find(node.name) != nodes.end() )
if ( nodes.contains(node.name) )
return util::fmt("node with name '%s' already exists", node.name.data());
if ( node.interface.has_value() && node.pcap_file.has_value() )

View file

@ -73,7 +73,7 @@ bool labels_valid(std::span<const zeek::telemetry::LabelView> labels,
return std::find(keys.begin(), keys.end(), x.first) != keys.end();
};
return labels.size() == label_names.size()
&& std::all_of(labels.begin(), labels.end(), key_in_label_names);
&& std::ranges::all_of(labels, key_in_label_names);
}
template <class IntOrDbl>

View file

@ -275,11 +275,11 @@ static bool show_plugins(int level) {
int count = 0;
for ( plugin::Manager::plugin_list::const_iterator i = plugins.begin(); i != plugins.end(); i++ ) {
if ( requested_plugins.size() && requested_plugins.find((*i)->Name()) == requested_plugins.end() )
for ( const auto& plugin : plugins ) {
if ( ! requested_plugins.empty() && ! requested_plugins.contains(plugin->Name()) )
continue;
(*i)->Describe(&d);
plugin->Describe(&d);
if ( ! d.IsShort() )
d.Add("\n");

View file

@ -9,13 +9,14 @@
%%{ // C++ segment
#include <sys/stat.h>
#include <string>
#include <algorithm>
#include <cinttypes>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <numbers>
#include <string>
#include <vector>
#include "zeek/digest.h"
@ -4222,7 +4223,7 @@ function blocking_lookup_hostname%(host: string%) : addr_set
## .. zeek:see:: haversine_distance_ip
function haversine_distance%(lat1: double, long1: double, lat2: double, long2: double%): double
%{
const double PI = 3.14159;
const double PI = std::numbers::pi;
const double RADIUS = 3958.8; // Earth's radius in miles.
double s1 = sin((lat2 - lat1) * PI/360);

View file

@ -494,7 +494,7 @@ void ScriptTarget::DoGenerate() const {
}
for ( const auto& f : dir_contents ) {
if ( targets.find(f) != targets.end() )
if ( targets.contains(f) )
continue;
if ( unlink(f.c_str()) < 0 )

View file

@ -3,6 +3,6 @@
5.8481e+03
1.9193e-02
1.5136e-02
9.2419e-01
9.0763e-01
1.2437e+04
1.2437e+04

View file

@ -912,7 +912,7 @@ Type* Type::LookUpByID(ID* id) {
}
void Type::AddPredefinedType(const string& type_name, Type* type) {
ASSERT(type_map_.find(type_name) == type_map_.end());
ASSERT(! type_map_.contains(type_name));
type_map_[type_name] = type;
}