Skip to content

Commit

Permalink
src: rename AliasedBufferInfo->AliasedBufferIndex
Browse files Browse the repository at this point in the history
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<V8T>(*info_).ToLocalChecked();

Even knowing that GetDataFromSnapshotOnce takes a size_t I had to double
check the type of info_ to make sure.

PR-URL: #36339
Reviewed-By: Zeyu Yang <himself65@outlook.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
  • Loading branch information
danbev authored and danielleadams committed Dec 7, 2020
1 parent 4ca1bd8 commit a03aa0a
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 31 deletions.
42 changes: 21 additions & 21 deletions src/aliased_buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
}
Expand Down Expand Up @@ -72,12 +72,12 @@ class AliasedBufferBase {
const size_t byte_offset,
const size_t count,
const AliasedBufferBase<uint8_t, v8::Uint8Array>& 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;
}
Expand All @@ -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<V8T>(that.isolate_, that.GetJSArray());
}

AliasedBufferInfo Serialize(v8::Local<v8::Context> context,
AliasedBufferIndex Serialize(v8::Local<v8::Context> context,
v8::SnapshotCreator* creator) {
DCHECK_NULL(info_);
DCHECK_NULL(index_);
return creator->AddData(context, GetJSArray());
}

inline void Deserialize(v8::Local<v8::Context> context) {
DCHECK_NOT_NULL(info_);
DCHECK_NOT_NULL(index_);
v8::Local<V8T> arr =
context->GetDataFromSnapshotOnce<V8T>(*info_).ToLocalChecked();
context->GetDataFromSnapshotOnce<V8T>(*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());
Expand All @@ -124,11 +124,11 @@ class AliasedBufferBase {
static_cast<uint8_t*>(arr->Buffer()->GetBackingStore()->Data());
buffer_ = reinterpret_cast<NativeT*>(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_;
Expand Down Expand Up @@ -194,7 +194,7 @@ class AliasedBufferBase {
* Get the underlying v8 TypedArray overlayed on top of the native buffer
*/
v8::Local<V8T> GetJSArray() const {
DCHECK_NULL(info_);
DCHECK_NULL(index_);
return js_array_.Get(isolate_);
}

Expand All @@ -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_;
}

Expand All @@ -227,15 +227,15 @@ class AliasedBufferBase {
*/
inline void SetValue(const size_t index, NativeT value) {
DCHECK_LT(index, count_);
DCHECK_NULL(info_);
DCHECK_NULL(index_);
buffer_[index] = value;
}

/**
* 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];
}
Expand All @@ -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);
}

Expand All @@ -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_);
Expand Down Expand Up @@ -296,7 +296,7 @@ class AliasedBufferBase {
v8::Global<V8T> js_array_;

// Deserialize data
const AliasedBufferInfo* info_ = nullptr;
const AliasedBufferIndex* index_ = nullptr;
};

typedef AliasedBufferBase<int32_t, v8::Int32Array> AliasedInt32Array;
Expand Down
14 changes: 7 additions & 7 deletions src/env.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<SnapshotIndex> native_execution_async_resources;
};
Expand Down Expand Up @@ -807,7 +807,7 @@ class ImmediateInfo : public MemoryRetainer {
void MemoryInfo(MemoryTracker* tracker) const override;

struct SerializeInfo {
AliasedBufferInfo fields;
AliasedBufferIndex fields;
};
SerializeInfo Serialize(v8::Local<v8::Context> context,
v8::SnapshotCreator* creator);
Expand Down Expand Up @@ -839,7 +839,7 @@ class TickInfo : public MemoryRetainer {
~TickInfo() = default;

struct SerializeInfo {
AliasedBufferInfo fields;
AliasedBufferIndex fields;
};
SerializeInfo Serialize(v8::Local<v8::Context> context,
v8::SnapshotCreator* creator);
Expand Down Expand Up @@ -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<PropInfo> persistent_templates;
std::vector<PropInfo> persistent_values;
Expand Down
6 changes: 3 additions & 3 deletions src/node_perf_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit a03aa0a

Please sign in to comment.