Skip to content

Commit 1e5f632

Browse files
iknoomRafaelGSS
authored andcommitted
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: #59304 Reviewed-By: Zeyu "Alex" Yang <[email protected]> Reviewed-By: Franziska Hinkelmann <[email protected]>
1 parent 0eb5962 commit 1e5f632

File tree

7 files changed

+8
-10
lines changed

7 files changed

+8
-10
lines changed

src/inspector/io_agent.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ DispatchResponse IoAgent::read(const String& in_handle,
2727
if (in_offset.has_value()) {
2828
offset = *in_offset;
2929
offset_was_specified = true;
30-
} else if (offset_map_.find(url) != offset_map_.end()) {
30+
} else if (offset_map_.contains(url)) {
3131
offset = offset_map_[url];
3232
}
3333
int size = 1 << 20;

src/inspector_profiler.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,7 @@ class V8ProfilerConnection {
6565
simdjson::ondemand::object* result);
6666
virtual void WriteProfile(simdjson::ondemand::object* result);
6767

68-
bool HasProfileId(uint64_t id) const {
69-
return profile_ids_.find(id) != profile_ids_.end();
70-
}
68+
bool HasProfileId(uint64_t id) const { return profile_ids_.contains(id); }
7169

7270
void RemoveProfileId(uint64_t id) { profile_ids_.erase(id); }
7371

src/node_blob.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -537,11 +537,11 @@ void BlobBindingData::store_data_object(
537537
}
538538

539539
void BlobBindingData::revoke_data_object(const std::string& uuid) {
540-
if (data_objects_.find(uuid) == data_objects_.end()) {
540+
if (!data_objects_.contains(uuid)) {
541541
return;
542542
}
543543
data_objects_.erase(uuid);
544-
CHECK_EQ(data_objects_.find(uuid), data_objects_.end());
544+
CHECK(!data_objects_.contains(uuid));
545545
}
546546

547547
BlobBindingData::StoredDataObject BlobBindingData::get_data_object(

src/node_builtins.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ MaybeLocal<Function> BuiltinLoader::LookupAndCompileInternal(
306306
if (should_eager_compile_) {
307307
options = ScriptCompiler::kEagerCompile;
308308
} else if (!to_eager_compile_.empty()) {
309-
if (to_eager_compile_.find(id) != to_eager_compile_.end()) {
309+
if (to_eager_compile_.contains(id)) {
310310
options = ScriptCompiler::kEagerCompile;
311311
}
312312
}

src/node_env_var.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ void MapKVStore::Set(Isolate* isolate, Local<String> key, Local<String> value) {
273273

274274
int32_t MapKVStore::Query(const char* key) const {
275275
Mutex::ScopedLock lock(mutex_);
276-
return map_.find(key) == map_.end() ? -1 : 0;
276+
return map_.contains(key) ? 0 : -1;
277277
}
278278

279279
int32_t MapKVStore::Query(Isolate* isolate, Local<String> key) const {

src/node_messaging.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1505,7 +1505,7 @@ Maybe<bool> SiblingGroup::Dispatch(
15051505
RwLock::ScopedReadLock lock(group_mutex_);
15061506

15071507
// The source MessagePortData is not part of this group.
1508-
if (ports_.find(source) == ports_.end()) {
1508+
if (!ports_.contains(source)) {
15091509
if (error != nullptr)
15101510
*error = "Source MessagePort is not entangled with this group.";
15111511
return Nothing<bool>();

src/signal_wrap.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ void DecreaseSignalHandlerCount(int signum) {
170170

171171
bool HasSignalJSHandler(int signum) {
172172
Mutex::ScopedLock lock(handled_signals_mutex);
173-
return handled_signals.find(signum) != handled_signals.end();
173+
return handled_signals.contains(signum);
174174
}
175175
} // namespace node
176176

0 commit comments

Comments
 (0)