src: use C++20 contains() method

Refactors several `v.find(...) == v.end()` and `v.find(...) != v.end()`
to use more expressive and readable C++20 `contains()` method.

PR-URL: https://github.com/nodejs/node/pull/59304
Reviewed-By: Zeyu "Alex" Yang <himself65@outlook.com>
Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com>
This commit is contained in:
iknoom
2025-08-01 04:09:40 +09:00
committed by Antoine du Hamel
parent 99c80e3a45
commit 5bea645e4b
7 changed files with 8 additions and 10 deletions

View File

@@ -27,7 +27,7 @@ DispatchResponse IoAgent::read(const String& in_handle,
if (in_offset.has_value()) {
offset = *in_offset;
offset_was_specified = true;
} else if (offset_map_.find(url) != offset_map_.end()) {
} else if (offset_map_.contains(url)) {
offset = offset_map_[url];
}
int size = 1 << 20;

View File

@@ -65,9 +65,7 @@ class V8ProfilerConnection {
simdjson::ondemand::object* result);
virtual void WriteProfile(simdjson::ondemand::object* result);
bool HasProfileId(uint64_t id) const {
return profile_ids_.find(id) != profile_ids_.end();
}
bool HasProfileId(uint64_t id) const { return profile_ids_.contains(id); }
void RemoveProfileId(uint64_t id) { profile_ids_.erase(id); }

View File

@@ -537,11 +537,11 @@ void BlobBindingData::store_data_object(
}
void BlobBindingData::revoke_data_object(const std::string& uuid) {
if (data_objects_.find(uuid) == data_objects_.end()) {
if (!data_objects_.contains(uuid)) {
return;
}
data_objects_.erase(uuid);
CHECK_EQ(data_objects_.find(uuid), data_objects_.end());
CHECK(!data_objects_.contains(uuid));
}
BlobBindingData::StoredDataObject BlobBindingData::get_data_object(

View File

@@ -307,7 +307,7 @@ MaybeLocal<Function> BuiltinLoader::LookupAndCompileInternal(
if (should_eager_compile_) {
options = ScriptCompiler::kEagerCompile;
} else if (!to_eager_compile_.empty()) {
if (to_eager_compile_.find(id) != to_eager_compile_.end()) {
if (to_eager_compile_.contains(id)) {
options = ScriptCompiler::kEagerCompile;
}
}

View File

@@ -273,7 +273,7 @@ void MapKVStore::Set(Isolate* isolate, Local<String> key, Local<String> value) {
int32_t MapKVStore::Query(const char* key) const {
Mutex::ScopedLock lock(mutex_);
return map_.find(key) == map_.end() ? -1 : 0;
return map_.contains(key) ? 0 : -1;
}
int32_t MapKVStore::Query(Isolate* isolate, Local<String> key) const {

View File

@@ -1505,7 +1505,7 @@ Maybe<bool> SiblingGroup::Dispatch(
RwLock::ScopedReadLock lock(group_mutex_);
// The source MessagePortData is not part of this group.
if (ports_.find(source) == ports_.end()) {
if (!ports_.contains(source)) {
if (error != nullptr)
*error = "Source MessagePort is not entangled with this group.";
return Nothing<bool>();

View File

@@ -170,7 +170,7 @@ void DecreaseSignalHandlerCount(int signum) {
bool HasSignalJSHandler(int signum) {
Mutex::ScopedLock lock(handled_signals_mutex);
return handled_signals.find(signum) != handled_signals.end();
return handled_signals.contains(signum);
}
} // namespace node