@@ -87,13 +87,13 @@ void AsyncHooks::ResetPromiseHooks(Local<Function> init,
87
87
js_promise_hooks_[3 ].Reset (env ()->isolate (), resolve);
88
88
}
89
89
90
- Local<Array> AsyncHooks::GetPromiseHooks (Isolate* isolate) {
91
- std::vector<Local< Value>> values;
90
+ Local<Array> AsyncHooks::GetPromiseHooks (Isolate* isolate) const {
91
+ v8::LocalVector< Value> values (isolate, js_promise_hooks_. size ()) ;
92
92
for (size_t i = 0 ; i < js_promise_hooks_.size (); ++i) {
93
93
if (js_promise_hooks_[i].IsEmpty ()) {
94
- values. push_back ( Undefined (isolate) );
94
+ values[i] = Undefined (isolate);
95
95
} else {
96
- values. push_back ( js_promise_hooks_[i].Get (isolate) );
96
+ values[i] = js_promise_hooks_[i].Get (isolate);
97
97
}
98
98
}
99
99
return Array::New (isolate, values.data (), values.size ());
@@ -236,13 +236,10 @@ void Environment::TrackContext(Local<Context> context) {
236
236
237
237
void Environment::UntrackContext (Local<Context> context) {
238
238
HandleScope handle_scope (isolate_);
239
- contexts_.erase (std::remove_if (contexts_.begin (),
240
- contexts_.end (),
241
- [&](auto && el) { return el.IsEmpty (); }),
242
- contexts_.end ());
239
+ std::erase_if (contexts_, [&](auto && el) { return el.IsEmpty (); });
243
240
for (auto it = contexts_.begin (); it != contexts_.end (); it++) {
244
- Local<Context> saved_context = PersistentToLocal::Weak (isolate_, *it);
245
- if ( saved_context == context) {
241
+ if ( Local<Context> saved_context = PersistentToLocal::Weak (isolate_, *it);
242
+ saved_context == context) {
246
243
it->Reset ();
247
244
contexts_.erase (it);
248
245
break ;
@@ -351,9 +348,11 @@ IsolateDataSerializeInfo IsolateData::Serialize(SnapshotCreator* creator) {
351
348
#undef VS
352
349
#undef VP
353
350
354
- for (size_t i = 0 ; i < AsyncWrap::PROVIDERS_LENGTH; i++)
351
+ info.primitive_values .reserve (info.primitive_values .size () +
352
+ AsyncWrap::PROVIDERS_LENGTH);
353
+ for (size_t i = 0 ; i < AsyncWrap::PROVIDERS_LENGTH; i++) {
355
354
info.primitive_values .push_back (creator->AddData (async_wrap_provider (i)));
356
-
355
+ }
357
356
uint32_t id = 0 ;
358
357
#define VM (PropertyName ) V(PropertyName##_binding_template, ObjectTemplate)
359
358
#define V (PropertyName, TypeName ) \
@@ -375,7 +374,7 @@ IsolateDataSerializeInfo IsolateData::Serialize(SnapshotCreator* creator) {
375
374
void IsolateData::DeserializeProperties (const IsolateDataSerializeInfo* info) {
376
375
size_t i = 0 ;
377
376
378
- v8:: Isolate::Scope isolate_scope (isolate_);
377
+ Isolate::Scope isolate_scope (isolate_);
379
378
HandleScope handle_scope (isolate_);
380
379
381
380
if (per_process::enabled_debug_list.enabled (DebugCategory::MKSNAPSHOT)) {
@@ -721,9 +720,8 @@ void Environment::TryLoadAddon(
721
720
std::string Environment::GetCwd (const std::string& exec_path) {
722
721
char cwd[PATH_MAX_BYTES];
723
722
size_t size = PATH_MAX_BYTES;
724
- const int err = uv_cwd (cwd, &size);
725
723
726
- if (err == 0 ) {
724
+ if (uv_cwd (cwd, &size) == 0 ) {
727
725
CHECK_GT (size, 0 );
728
726
return cwd;
729
727
}
@@ -769,7 +767,7 @@ std::string Environment::GetExecPath(const std::vector<std::string>& argv) {
769
767
std::string exec_path;
770
768
if (uv_exepath (exec_path_buf, &exec_path_len) == 0 ) {
771
769
exec_path = std::string (exec_path_buf, exec_path_len);
772
- } else if (argv.size () > 0 ) {
770
+ } else if (! argv.empty () ) {
773
771
exec_path = argv[0 ];
774
772
}
775
773
@@ -1239,7 +1237,8 @@ void Environment::StartProfilerIdleNotifier() {
1239
1237
}
1240
1238
1241
1239
void Environment::PrintSyncTrace () const {
1242
- if (!trace_sync_io_) return ;
1240
+ if (!trace_sync_io_) [[likely]]
1241
+ return ;
1243
1242
1244
1243
HandleScope handle_scope (isolate ());
1245
1244
@@ -1314,7 +1313,7 @@ void Environment::AtExit(void (*cb)(void* arg), void* arg) {
1314
1313
at_exit_functions_.push_front (ExitCallback{cb, arg});
1315
1314
}
1316
1315
1317
- Maybe<bool > Environment::CheckUnsettledTopLevelAwait () {
1316
+ Maybe<bool > Environment::CheckUnsettledTopLevelAwait () const {
1318
1317
HandleScope scope (isolate_);
1319
1318
Local<Context> ctx = context ();
1320
1319
Local<Value> value;
@@ -1516,7 +1515,7 @@ void Environment::RunTimers(uv_timer_t* handle) {
1516
1515
int64_t expiry_ms =
1517
1516
ret.ToLocalChecked ()->IntegerValue (env->context ()).FromJust ();
1518
1517
1519
- uv_handle_t * h = reinterpret_cast <uv_handle_t *>(handle);
1518
+ auto * h = reinterpret_cast <uv_handle_t *>(handle);
1520
1519
1521
1520
if (expiry_ms != 0 ) {
1522
1521
int64_t duration_ms =
@@ -1582,8 +1581,7 @@ Local<Value> Environment::GetNow() {
1582
1581
uint64_t now = GetNowUint64 ();
1583
1582
if (now <= 0xffffffff )
1584
1583
return Integer::NewFromUnsigned (isolate (), static_cast <uint32_t >(now));
1585
- else
1586
- return Number::New (isolate (), static_cast <double >(now));
1584
+ return Number::New (isolate (), static_cast <double >(now));
1587
1585
}
1588
1586
1589
1587
void CollectExceptionInfo (Environment* env,
@@ -1642,8 +1640,8 @@ void Environment::CollectUVExceptionInfo(Local<Value> object,
1642
1640
message = uv_strerror (errorno);
1643
1641
}
1644
1642
1645
- node:: CollectExceptionInfo (this , obj, errorno, err_string,
1646
- syscall , message, path, dest);
1643
+ CollectExceptionInfo (
1644
+ this , obj, errorno, err_string, syscall , message, path, dest);
1647
1645
}
1648
1646
1649
1647
ImmediateInfo::ImmediateInfo (Isolate* isolate, const SerializeInfo* info)
@@ -1973,7 +1971,7 @@ void Environment::BuildEmbedderGraph(Isolate* isolate,
1973
1971
EmbedderGraph* graph,
1974
1972
void * data) {
1975
1973
MemoryTracker tracker (isolate, graph);
1976
- Environment * env = static_cast <Environment*>(data);
1974
+ auto * env = static_cast <Environment*>(data);
1977
1975
// Start traversing embedder objects from the root Environment object.
1978
1976
tracker.Track (env);
1979
1977
}
@@ -2035,7 +2033,7 @@ void Environment::TracePromises(PromiseHookType type,
2035
2033
size_t Environment::NearHeapLimitCallback (void * data,
2036
2034
size_t current_heap_limit,
2037
2035
size_t initial_heap_limit) {
2038
- Environment * env = static_cast <Environment*>(data);
2036
+ auto * env = static_cast <Environment*>(data);
2039
2037
2040
2038
Debug (env,
2041
2039
DebugCategory::DIAGNOSTICS,
@@ -2081,8 +2079,8 @@ size_t Environment::NearHeapLimitCallback(void* data,
2081
2079
DebugCategory::DIAGNOSTICS,
2082
2080
" Estimated available memory=%" PRIu64 " , "
2083
2081
" estimated overhead=%" PRIu64 " \n " ,
2084
- static_cast < uint64_t >( available) ,
2085
- static_cast < uint64_t >( estimated_overhead) );
2082
+ available,
2083
+ estimated_overhead);
2086
2084
2087
2085
// This might be hit when the snapshot is being taken in another
2088
2086
// NearHeapLimitCallback invocation.
0 commit comments