@@ -87,13 +87,13 @@ void AsyncHooks::ResetPromiseHooks(Local<Function> init,
8787 js_promise_hooks_[3 ].Reset (env ()->isolate (), resolve);
8888}
8989
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 ()) ;
9292 for (size_t i = 0 ; i < js_promise_hooks_.size (); ++i) {
9393 if (js_promise_hooks_[i].IsEmpty ()) {
94- values. push_back ( Undefined (isolate) );
94+ values[i] = Undefined (isolate);
9595 } else {
96- values. push_back ( js_promise_hooks_[i].Get (isolate) );
96+ values[i] = js_promise_hooks_[i].Get (isolate);
9797 }
9898 }
9999 return Array::New (isolate, values.data (), values.size ());
@@ -236,13 +236,10 @@ void Environment::TrackContext(Local<Context> context) {
236236
237237void Environment::UntrackContext (Local<Context> context) {
238238 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 (); });
243240 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) {
246243 it->Reset ();
247244 contexts_.erase (it);
248245 break ;
@@ -351,9 +348,11 @@ IsolateDataSerializeInfo IsolateData::Serialize(SnapshotCreator* creator) {
351348#undef VS
352349#undef VP
353350
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++) {
355354 info.primitive_values .push_back (creator->AddData (async_wrap_provider (i)));
356-
355+ }
357356 uint32_t id = 0 ;
358357#define VM (PropertyName ) V(PropertyName##_binding_template, ObjectTemplate)
359358#define V (PropertyName, TypeName ) \
@@ -375,7 +374,7 @@ IsolateDataSerializeInfo IsolateData::Serialize(SnapshotCreator* creator) {
375374void IsolateData::DeserializeProperties (const IsolateDataSerializeInfo* info) {
376375 size_t i = 0 ;
377376
378- v8:: Isolate::Scope isolate_scope (isolate_);
377+ Isolate::Scope isolate_scope (isolate_);
379378 HandleScope handle_scope (isolate_);
380379
381380 if (per_process::enabled_debug_list.enabled (DebugCategory::MKSNAPSHOT)) {
@@ -721,9 +720,8 @@ void Environment::TryLoadAddon(
721720std::string Environment::GetCwd (const std::string& exec_path) {
722721 char cwd[PATH_MAX_BYTES];
723722 size_t size = PATH_MAX_BYTES;
724- const int err = uv_cwd (cwd, &size);
725723
726- if (err == 0 ) {
724+ if (uv_cwd (cwd, &size) == 0 ) {
727725 CHECK_GT (size, 0 );
728726 return cwd;
729727 }
@@ -769,7 +767,7 @@ std::string Environment::GetExecPath(const std::vector<std::string>& argv) {
769767 std::string exec_path;
770768 if (uv_exepath (exec_path_buf, &exec_path_len) == 0 ) {
771769 exec_path = std::string (exec_path_buf, exec_path_len);
772- } else if (argv.size () > 0 ) {
770+ } else if (! argv.empty () ) {
773771 exec_path = argv[0 ];
774772 }
775773
@@ -1239,7 +1237,8 @@ void Environment::StartProfilerIdleNotifier() {
12391237}
12401238
12411239void Environment::PrintSyncTrace () const {
1242- if (!trace_sync_io_) return ;
1240+ if (!trace_sync_io_) [[likely]]
1241+ return ;
12431242
12441243 HandleScope handle_scope (isolate ());
12451244
@@ -1314,7 +1313,7 @@ void Environment::AtExit(void (*cb)(void* arg), void* arg) {
13141313 at_exit_functions_.push_front (ExitCallback{cb, arg});
13151314}
13161315
1317- Maybe<bool > Environment::CheckUnsettledTopLevelAwait () {
1316+ Maybe<bool > Environment::CheckUnsettledTopLevelAwait () const {
13181317 HandleScope scope (isolate_);
13191318 Local<Context> ctx = context ();
13201319 Local<Value> value;
@@ -1516,7 +1515,7 @@ void Environment::RunTimers(uv_timer_t* handle) {
15161515 int64_t expiry_ms =
15171516 ret.ToLocalChecked ()->IntegerValue (env->context ()).FromJust ();
15181517
1519- uv_handle_t * h = reinterpret_cast <uv_handle_t *>(handle);
1518+ auto * h = reinterpret_cast <uv_handle_t *>(handle);
15201519
15211520 if (expiry_ms != 0 ) {
15221521 int64_t duration_ms =
@@ -1582,8 +1581,7 @@ Local<Value> Environment::GetNow() {
15821581 uint64_t now = GetNowUint64 ();
15831582 if (now <= 0xffffffff )
15841583 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));
15871585}
15881586
15891587void CollectExceptionInfo (Environment* env,
@@ -1642,8 +1640,8 @@ void Environment::CollectUVExceptionInfo(Local<Value> object,
16421640 message = uv_strerror (errorno);
16431641 }
16441642
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);
16471645}
16481646
16491647ImmediateInfo::ImmediateInfo (Isolate* isolate, const SerializeInfo* info)
@@ -1973,7 +1971,7 @@ void Environment::BuildEmbedderGraph(Isolate* isolate,
19731971 EmbedderGraph* graph,
19741972 void * data) {
19751973 MemoryTracker tracker (isolate, graph);
1976- Environment * env = static_cast <Environment*>(data);
1974+ auto * env = static_cast <Environment*>(data);
19771975 // Start traversing embedder objects from the root Environment object.
19781976 tracker.Track (env);
19791977}
@@ -2035,7 +2033,7 @@ void Environment::TracePromises(PromiseHookType type,
20352033size_t Environment::NearHeapLimitCallback (void * data,
20362034 size_t current_heap_limit,
20372035 size_t initial_heap_limit) {
2038- Environment * env = static_cast <Environment*>(data);
2036+ auto * env = static_cast <Environment*>(data);
20392037
20402038 Debug (env,
20412039 DebugCategory::DIAGNOSTICS,
@@ -2081,8 +2079,8 @@ size_t Environment::NearHeapLimitCallback(void* data,
20812079 DebugCategory::DIAGNOSTICS,
20822080 " Estimated available memory=%" PRIu64 " , "
20832081 " estimated overhead=%" PRIu64 " \n " ,
2084- static_cast < uint64_t >( available) ,
2085- static_cast < uint64_t >( estimated_overhead) );
2082+ available,
2083+ estimated_overhead);
20862084
20872085 // This might be hit when the snapshot is being taken in another
20882086 // NearHeapLimitCallback invocation.
0 commit comments