src: use C++20 `contains()` method · nodejs/node@1e5f632

7 files changed

lines changed

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;

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

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

}

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 {

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

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