From a03aa0a6b2b2cfca66d5db6afe7d89b7f19831d3 Mon Sep 17 00:00:00 2001 From: Daniel Bevenius Date: Tue, 1 Dec 2020 12:47:09 +0100 Subject: [PATCH] src: rename AliasedBufferInfo->AliasedBufferIndex This commit suggest renaming AlaisedBufferInfo to AlaisedBufferIndex to make the code more readable. The main motivation for this change is that I personally think that the following code could be a little clearer: context->GetDataFromSnapshotOnce(*info_).ToLocalChecked(); Even knowing that GetDataFromSnapshotOnce takes a size_t I had to double check the type of info_ to make sure. PR-URL: https://github.com/nodejs/node/pull/36339 Reviewed-By: Zeyu Yang Reviewed-By: Rich Trott --- src/aliased_buffer.h | 42 +++++++++++++++++++++--------------------- src/env.h | 14 +++++++------- src/node_perf_common.h | 6 +++--- 3 files changed, 31 insertions(+), 31 deletions(-) diff --git a/src/aliased_buffer.h b/src/aliased_buffer.h index 408f158b7880ca..134685542d4a75 100644 --- a/src/aliased_buffer.h +++ b/src/aliased_buffer.h @@ -10,7 +10,7 @@ namespace node { -typedef size_t AliasedBufferInfo; +typedef size_t AliasedBufferIndex; /** * Do not use this class directly when creating instances of it - use the @@ -37,10 +37,10 @@ class AliasedBufferBase { public: AliasedBufferBase(v8::Isolate* isolate, const size_t count, - const AliasedBufferInfo* info = nullptr) - : isolate_(isolate), count_(count), byte_offset_(0), info_(info) { + const AliasedBufferIndex* index = nullptr) + : isolate_(isolate), count_(count), byte_offset_(0), index_(index) { CHECK_GT(count, 0); - if (info != nullptr) { + if (index != nullptr) { // Will be deserialized later. return; } @@ -72,12 +72,12 @@ class AliasedBufferBase { const size_t byte_offset, const size_t count, const AliasedBufferBase& backing_buffer, - const AliasedBufferInfo* info = nullptr) + const AliasedBufferIndex* index = nullptr) : isolate_(isolate), count_(count), byte_offset_(byte_offset), - info_(info) { - if (info != nullptr) { + index_(index) { + if (index != nullptr) { // Will be deserialized later. return; } @@ -102,20 +102,20 @@ class AliasedBufferBase { count_(that.count_), byte_offset_(that.byte_offset_), buffer_(that.buffer_) { - DCHECK_NULL(info_); + DCHECK_NULL(index_); js_array_ = v8::Global(that.isolate_, that.GetJSArray()); } - AliasedBufferInfo Serialize(v8::Local context, + AliasedBufferIndex Serialize(v8::Local context, v8::SnapshotCreator* creator) { - DCHECK_NULL(info_); + DCHECK_NULL(index_); return creator->AddData(context, GetJSArray()); } inline void Deserialize(v8::Local context) { - DCHECK_NOT_NULL(info_); + DCHECK_NOT_NULL(index_); v8::Local arr = - context->GetDataFromSnapshotOnce(*info_).ToLocalChecked(); + context->GetDataFromSnapshotOnce(*index_).ToLocalChecked(); // These may not hold true for AliasedBuffers that have grown, so should // be removed when we expand the snapshot support. DCHECK_EQ(count_, arr->Length()); @@ -124,11 +124,11 @@ class AliasedBufferBase { static_cast(arr->Buffer()->GetBackingStore()->Data()); buffer_ = reinterpret_cast(raw + byte_offset_); js_array_.Reset(isolate_, arr); - info_ = nullptr; + index_ = nullptr; } AliasedBufferBase& operator=(AliasedBufferBase&& that) noexcept { - DCHECK_NULL(info_); + DCHECK_NULL(index_); this->~AliasedBufferBase(); isolate_ = that.isolate_; count_ = that.count_; @@ -194,7 +194,7 @@ class AliasedBufferBase { * Get the underlying v8 TypedArray overlayed on top of the native buffer */ v8::Local GetJSArray() const { - DCHECK_NULL(info_); + DCHECK_NULL(index_); return js_array_.Get(isolate_); } @@ -211,7 +211,7 @@ class AliasedBufferBase { * through the GetValue/SetValue/operator[] methods */ inline const NativeT* GetNativeBuffer() const { - DCHECK_NULL(info_); + DCHECK_NULL(index_); return buffer_; } @@ -227,7 +227,7 @@ class AliasedBufferBase { */ inline void SetValue(const size_t index, NativeT value) { DCHECK_LT(index, count_); - DCHECK_NULL(info_); + DCHECK_NULL(index_); buffer_[index] = value; } @@ -235,7 +235,7 @@ class AliasedBufferBase { * Get value at position index */ inline const NativeT GetValue(const size_t index) const { - DCHECK_NULL(info_); + DCHECK_NULL(index_); DCHECK_LT(index, count_); return buffer_[index]; } @@ -244,7 +244,7 @@ class AliasedBufferBase { * Effectively, a synonym for GetValue/SetValue */ Reference operator[](size_t index) { - DCHECK_NULL(info_); + DCHECK_NULL(index_); return Reference(this, index); } @@ -260,7 +260,7 @@ class AliasedBufferBase { // Should only be used on an owning array, not one created as a sub array of // an owning `AliasedBufferBase`. void reserve(size_t new_capacity) { - DCHECK_NULL(info_); + DCHECK_NULL(index_); DCHECK_GE(new_capacity, count_); DCHECK_EQ(byte_offset_, 0); const v8::HandleScope handle_scope(isolate_); @@ -296,7 +296,7 @@ class AliasedBufferBase { v8::Global js_array_; // Deserialize data - const AliasedBufferInfo* info_ = nullptr; + const AliasedBufferIndex* index_ = nullptr; }; typedef AliasedBufferBase AliasedInt32Array; diff --git a/src/env.h b/src/env.h index b3797e2c7e5880..e4dad52ac6816c 100644 --- a/src/env.h +++ b/src/env.h @@ -755,9 +755,9 @@ class AsyncHooks : public MemoryRetainer { }; struct SerializeInfo { - AliasedBufferInfo async_ids_stack; - AliasedBufferInfo fields; - AliasedBufferInfo async_id_fields; + AliasedBufferIndex async_ids_stack; + AliasedBufferIndex fields; + AliasedBufferIndex async_id_fields; SnapshotIndex js_execution_async_resources; std::vector native_execution_async_resources; }; @@ -807,7 +807,7 @@ class ImmediateInfo : public MemoryRetainer { void MemoryInfo(MemoryTracker* tracker) const override; struct SerializeInfo { - AliasedBufferInfo fields; + AliasedBufferIndex fields; }; SerializeInfo Serialize(v8::Local context, v8::SnapshotCreator* creator); @@ -839,7 +839,7 @@ class TickInfo : public MemoryRetainer { ~TickInfo() = default; struct SerializeInfo { - AliasedBufferInfo fields; + AliasedBufferIndex fields; }; SerializeInfo Serialize(v8::Local context, v8::SnapshotCreator* creator); @@ -931,8 +931,8 @@ struct EnvSerializeInfo { TickInfo::SerializeInfo tick_info; ImmediateInfo::SerializeInfo immediate_info; performance::PerformanceState::SerializeInfo performance_state; - AliasedBufferInfo stream_base_state; - AliasedBufferInfo should_abort_on_uncaught_toggle; + AliasedBufferIndex stream_base_state; + AliasedBufferIndex should_abort_on_uncaught_toggle; std::vector persistent_templates; std::vector persistent_values; diff --git a/src/node_perf_common.h b/src/node_perf_common.h index 5dc77c6fe91ef9..edc142d351268d 100644 --- a/src/node_perf_common.h +++ b/src/node_perf_common.h @@ -57,9 +57,9 @@ enum PerformanceEntryType { class PerformanceState { public: struct SerializeInfo { - AliasedBufferInfo root; - AliasedBufferInfo milestones; - AliasedBufferInfo observers; + AliasedBufferIndex root; + AliasedBufferIndex milestones; + AliasedBufferIndex observers; }; explicit PerformanceState(v8::Isolate* isolate, const SerializeInfo* info);