mirror of
https://github.com/zebrajr/node.git
synced 2026-01-15 12:15:26 +00:00
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:
@@ -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;
|
||||
|
||||
@@ -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); }
|
||||
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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>();
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user