Skip to content

Commit a03aa0a

Browse files
danbevdanielleadams
authored andcommitted
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<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>
1 parent 4ca1bd8 commit a03aa0a

File tree

3 files changed

+31
-31
lines changed

3 files changed

+31
-31
lines changed

src/aliased_buffer.h

+21-21
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
namespace node {
1212

13-
typedef size_t AliasedBufferInfo;
13+
typedef size_t AliasedBufferIndex;
1414

1515
/**
1616
* Do not use this class directly when creating instances of it - use the
@@ -37,10 +37,10 @@ class AliasedBufferBase {
3737
public:
3838
AliasedBufferBase(v8::Isolate* isolate,
3939
const size_t count,
40-
const AliasedBufferInfo* info = nullptr)
41-
: isolate_(isolate), count_(count), byte_offset_(0), info_(info) {
40+
const AliasedBufferIndex* index = nullptr)
41+
: isolate_(isolate), count_(count), byte_offset_(0), index_(index) {
4242
CHECK_GT(count, 0);
43-
if (info != nullptr) {
43+
if (index != nullptr) {
4444
// Will be deserialized later.
4545
return;
4646
}
@@ -72,12 +72,12 @@ class AliasedBufferBase {
7272
const size_t byte_offset,
7373
const size_t count,
7474
const AliasedBufferBase<uint8_t, v8::Uint8Array>& backing_buffer,
75-
const AliasedBufferInfo* info = nullptr)
75+
const AliasedBufferIndex* index = nullptr)
7676
: isolate_(isolate),
7777
count_(count),
7878
byte_offset_(byte_offset),
79-
info_(info) {
80-
if (info != nullptr) {
79+
index_(index) {
80+
if (index != nullptr) {
8181
// Will be deserialized later.
8282
return;
8383
}
@@ -102,20 +102,20 @@ class AliasedBufferBase {
102102
count_(that.count_),
103103
byte_offset_(that.byte_offset_),
104104
buffer_(that.buffer_) {
105-
DCHECK_NULL(info_);
105+
DCHECK_NULL(index_);
106106
js_array_ = v8::Global<V8T>(that.isolate_, that.GetJSArray());
107107
}
108108

109-
AliasedBufferInfo Serialize(v8::Local<v8::Context> context,
109+
AliasedBufferIndex Serialize(v8::Local<v8::Context> context,
110110
v8::SnapshotCreator* creator) {
111-
DCHECK_NULL(info_);
111+
DCHECK_NULL(index_);
112112
return creator->AddData(context, GetJSArray());
113113
}
114114

115115
inline void Deserialize(v8::Local<v8::Context> context) {
116-
DCHECK_NOT_NULL(info_);
116+
DCHECK_NOT_NULL(index_);
117117
v8::Local<V8T> arr =
118-
context->GetDataFromSnapshotOnce<V8T>(*info_).ToLocalChecked();
118+
context->GetDataFromSnapshotOnce<V8T>(*index_).ToLocalChecked();
119119
// These may not hold true for AliasedBuffers that have grown, so should
120120
// be removed when we expand the snapshot support.
121121
DCHECK_EQ(count_, arr->Length());
@@ -124,11 +124,11 @@ class AliasedBufferBase {
124124
static_cast<uint8_t*>(arr->Buffer()->GetBackingStore()->Data());
125125
buffer_ = reinterpret_cast<NativeT*>(raw + byte_offset_);
126126
js_array_.Reset(isolate_, arr);
127-
info_ = nullptr;
127+
index_ = nullptr;
128128
}
129129

130130
AliasedBufferBase& operator=(AliasedBufferBase&& that) noexcept {
131-
DCHECK_NULL(info_);
131+
DCHECK_NULL(index_);
132132
this->~AliasedBufferBase();
133133
isolate_ = that.isolate_;
134134
count_ = that.count_;
@@ -194,7 +194,7 @@ class AliasedBufferBase {
194194
* Get the underlying v8 TypedArray overlayed on top of the native buffer
195195
*/
196196
v8::Local<V8T> GetJSArray() const {
197-
DCHECK_NULL(info_);
197+
DCHECK_NULL(index_);
198198
return js_array_.Get(isolate_);
199199
}
200200

@@ -211,7 +211,7 @@ class AliasedBufferBase {
211211
* through the GetValue/SetValue/operator[] methods
212212
*/
213213
inline const NativeT* GetNativeBuffer() const {
214-
DCHECK_NULL(info_);
214+
DCHECK_NULL(index_);
215215
return buffer_;
216216
}
217217

@@ -227,15 +227,15 @@ class AliasedBufferBase {
227227
*/
228228
inline void SetValue(const size_t index, NativeT value) {
229229
DCHECK_LT(index, count_);
230-
DCHECK_NULL(info_);
230+
DCHECK_NULL(index_);
231231
buffer_[index] = value;
232232
}
233233

234234
/**
235235
* Get value at position index
236236
*/
237237
inline const NativeT GetValue(const size_t index) const {
238-
DCHECK_NULL(info_);
238+
DCHECK_NULL(index_);
239239
DCHECK_LT(index, count_);
240240
return buffer_[index];
241241
}
@@ -244,7 +244,7 @@ class AliasedBufferBase {
244244
* Effectively, a synonym for GetValue/SetValue
245245
*/
246246
Reference operator[](size_t index) {
247-
DCHECK_NULL(info_);
247+
DCHECK_NULL(index_);
248248
return Reference(this, index);
249249
}
250250

@@ -260,7 +260,7 @@ class AliasedBufferBase {
260260
// Should only be used on an owning array, not one created as a sub array of
261261
// an owning `AliasedBufferBase`.
262262
void reserve(size_t new_capacity) {
263-
DCHECK_NULL(info_);
263+
DCHECK_NULL(index_);
264264
DCHECK_GE(new_capacity, count_);
265265
DCHECK_EQ(byte_offset_, 0);
266266
const v8::HandleScope handle_scope(isolate_);
@@ -296,7 +296,7 @@ class AliasedBufferBase {
296296
v8::Global<V8T> js_array_;
297297

298298
// Deserialize data
299-
const AliasedBufferInfo* info_ = nullptr;
299+
const AliasedBufferIndex* index_ = nullptr;
300300
};
301301

302302
typedef AliasedBufferBase<int32_t, v8::Int32Array> AliasedInt32Array;

src/env.h

+7-7
Original file line numberDiff line numberDiff line change
@@ -755,9 +755,9 @@ class AsyncHooks : public MemoryRetainer {
755755
};
756756

757757
struct SerializeInfo {
758-
AliasedBufferInfo async_ids_stack;
759-
AliasedBufferInfo fields;
760-
AliasedBufferInfo async_id_fields;
758+
AliasedBufferIndex async_ids_stack;
759+
AliasedBufferIndex fields;
760+
AliasedBufferIndex async_id_fields;
761761
SnapshotIndex js_execution_async_resources;
762762
std::vector<SnapshotIndex> native_execution_async_resources;
763763
};
@@ -807,7 +807,7 @@ class ImmediateInfo : public MemoryRetainer {
807807
void MemoryInfo(MemoryTracker* tracker) const override;
808808

809809
struct SerializeInfo {
810-
AliasedBufferInfo fields;
810+
AliasedBufferIndex fields;
811811
};
812812
SerializeInfo Serialize(v8::Local<v8::Context> context,
813813
v8::SnapshotCreator* creator);
@@ -839,7 +839,7 @@ class TickInfo : public MemoryRetainer {
839839
~TickInfo() = default;
840840

841841
struct SerializeInfo {
842-
AliasedBufferInfo fields;
842+
AliasedBufferIndex fields;
843843
};
844844
SerializeInfo Serialize(v8::Local<v8::Context> context,
845845
v8::SnapshotCreator* creator);
@@ -931,8 +931,8 @@ struct EnvSerializeInfo {
931931
TickInfo::SerializeInfo tick_info;
932932
ImmediateInfo::SerializeInfo immediate_info;
933933
performance::PerformanceState::SerializeInfo performance_state;
934-
AliasedBufferInfo stream_base_state;
935-
AliasedBufferInfo should_abort_on_uncaught_toggle;
934+
AliasedBufferIndex stream_base_state;
935+
AliasedBufferIndex should_abort_on_uncaught_toggle;
936936

937937
std::vector<PropInfo> persistent_templates;
938938
std::vector<PropInfo> persistent_values;

src/node_perf_common.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@ enum PerformanceEntryType {
5757
class PerformanceState {
5858
public:
5959
struct SerializeInfo {
60-
AliasedBufferInfo root;
61-
AliasedBufferInfo milestones;
62-
AliasedBufferInfo observers;
60+
AliasedBufferIndex root;
61+
AliasedBufferIndex milestones;
62+
AliasedBufferIndex observers;
6363
};
6464

6565
explicit PerformanceState(v8::Isolate* isolate, const SerializeInfo* info);

0 commit comments

Comments
 (0)