src: use C++20 `contains()` method · nodejs/node@133d410 · GitHub
Skip to content

Commit 133d410

Browse files
iknoomaduh95
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 <himself65@outlook.com> Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com>
1 parent 46c339e commit 133d410

7 files changed

Lines changed: 8 additions & 10 deletions

File tree

src/inspector/io_agent.cc

Lines changed: 1 addition & 1 deletion

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
@@ -534,11 +534,11 @@ void BlobBindingData::store_data_object(
534534
}
535535

536536
void BlobBindingData::revoke_data_object(const std::string& uuid) {
537-
if (data_objects_.find(uuid) == data_objects_.end()) {
537+
if (!data_objects_.contains(uuid)) {
538538
return;
539539
}
540540
data_objects_.erase(uuid);
541-
CHECK_EQ(data_objects_.find(uuid), data_objects_.end());
541+
CHECK(!data_objects_.contains(uuid));
542542
}
543543

544544
BlobBindingData::StoredDataObject BlobBindingData::get_data_object(

src/node_builtins.cc

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

src/node_env_var.cc

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

259259
int32_t MapKVStore::Query(const char* key) const {
260260
Mutex::ScopedLock lock(mutex_);
261-
return map_.find(key) == map_.end() ? -1 : 0;
261+
return map_.contains(key) ? 0 : -1;
262262
}
263263

264264
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
@@ -1508,7 +1508,7 @@ Maybe<bool> SiblingGroup::Dispatch(
15081508
RwLock::ScopedReadLock lock(group_mutex_);
15091509

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

src/signal_wrap.cc

Lines changed: 1 addition & 1 deletion

0 commit comments

Comments
 (0)