Skip to content

Commit 6af0163

Browse files
Renegade334RafaelGSS
authored andcommitted
src: simplify adding fast APIs to ExternalReferenceRegistry
PR-URL: #58896 Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
1 parent 573171d commit 6af0163

13 files changed

+52
-188
lines changed

src/crypto/crypto_timing.cc

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,16 +68,18 @@ bool FastTimingSafeEqual(Local<Value> receiver,
6868
return CRYPTO_memcmp(a.data(), b.data(), a.length()) == 0;
6969
}
7070

71-
static CFunction fast_equal(CFunction::Make(FastTimingSafeEqual));
71+
static CFunction fast_timing_safe_equal(CFunction::Make(FastTimingSafeEqual));
7272

7373
void Initialize(Environment* env, Local<Object> target) {
74-
SetFastMethodNoSideEffect(
75-
env->context(), target, "timingSafeEqual", TimingSafeEqual, &fast_equal);
74+
SetFastMethodNoSideEffect(env->context(),
75+
target,
76+
"timingSafeEqual",
77+
TimingSafeEqual,
78+
&fast_timing_safe_equal);
7679
}
7780
void RegisterExternalReferences(ExternalReferenceRegistry* registry) {
7881
registry->Register(TimingSafeEqual);
79-
registry->Register(FastTimingSafeEqual);
80-
registry->Register(fast_equal.GetTypeInfo());
82+
registry->Register(fast_timing_safe_equal);
8183
}
8284
} // namespace Timing
8385

src/histogram.cc

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -117,22 +117,14 @@ void HistogramImpl::RegisterExternalReferences(
117117
registry->Register(GetPercentiles);
118118
registry->Register(GetPercentilesBigInt);
119119
registry->Register(DoReset);
120-
registry->Register(fast_reset_.GetTypeInfo());
121-
registry->Register(fast_get_count_.GetTypeInfo());
122-
registry->Register(fast_get_min_.GetTypeInfo());
123-
registry->Register(fast_get_max_.GetTypeInfo());
124-
registry->Register(fast_get_mean_.GetTypeInfo());
125-
registry->Register(fast_get_exceeds_.GetTypeInfo());
126-
registry->Register(fast_get_stddev_.GetTypeInfo());
127-
registry->Register(fast_get_percentile_.GetTypeInfo());
128-
registry->Register(FastReset);
129-
registry->Register(FastGetCount);
130-
registry->Register(FastGetMin);
131-
registry->Register(FastGetMax);
132-
registry->Register(FastGetMean);
133-
registry->Register(FastGetExceeds);
134-
registry->Register(FastGetStddev);
135-
registry->Register(FastGetPercentile);
120+
registry->Register(fast_reset_);
121+
registry->Register(fast_get_count_);
122+
registry->Register(fast_get_min_);
123+
registry->Register(fast_get_max_);
124+
registry->Register(fast_get_mean_);
125+
registry->Register(fast_get_exceeds_);
126+
registry->Register(fast_get_stddev_);
127+
registry->Register(fast_get_percentile_);
136128
is_registered = true;
137129
}
138130

@@ -302,10 +294,8 @@ void HistogramBase::RegisterExternalReferences(
302294
registry->Register(Add);
303295
registry->Register(Record);
304296
registry->Register(RecordDelta);
305-
registry->Register(fast_record_.GetTypeInfo());
306-
registry->Register(fast_record_delta_.GetTypeInfo());
307-
registry->Register(FastRecord);
308-
registry->Register(FastRecordDelta);
297+
registry->Register(fast_record_);
298+
registry->Register(fast_record_delta_);
309299
HistogramImpl::RegisterExternalReferences(registry);
310300
}
311301

@@ -356,10 +346,8 @@ void IntervalHistogram::RegisterExternalReferences(
356346
ExternalReferenceRegistry* registry) {
357347
registry->Register(Start);
358348
registry->Register(Stop);
359-
registry->Register(fast_start_.GetTypeInfo());
360-
registry->Register(fast_stop_.GetTypeInfo());
361-
registry->Register(FastStart);
362-
registry->Register(FastStop);
349+
registry->Register(fast_start_);
350+
registry->Register(fast_stop_);
363351
HistogramImpl::RegisterExternalReferences(registry);
364352
}
365353

src/node_buffer.cc

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1634,20 +1634,16 @@ void RegisterExternalReferences(ExternalReferenceRegistry* registry) {
16341634
registry->Register(SetBufferPrototype);
16351635

16361636
registry->Register(SlowByteLengthUtf8);
1637-
registry->Register(fast_byte_length_utf8.GetTypeInfo());
1638-
registry->Register(FastByteLengthUtf8);
1637+
registry->Register(fast_byte_length_utf8);
16391638
registry->Register(SlowCopy);
1640-
registry->Register(fast_copy.GetTypeInfo());
1641-
registry->Register(FastCopy);
1639+
registry->Register(fast_copy);
16421640
registry->Register(Compare);
1643-
registry->Register(FastCompare);
1644-
registry->Register(fast_compare.GetTypeInfo());
1641+
registry->Register(fast_compare);
16451642
registry->Register(CompareOffset);
16461643
registry->Register(Fill);
16471644
registry->Register(IndexOfBuffer);
16481645
registry->Register(SlowIndexOfNumber);
1649-
registry->Register(FastIndexOfNumber);
1650-
registry->Register(fast_index_of_number.GetTypeInfo());
1646+
registry->Register(fast_index_of_number);
16511647
registry->Register(IndexOfString);
16521648

16531649
registry->Register(Swap16);
@@ -1668,12 +1664,9 @@ void RegisterExternalReferences(ExternalReferenceRegistry* registry) {
16681664
registry->Register(SlowWriteString<ASCII>);
16691665
registry->Register(SlowWriteString<LATIN1>);
16701666
registry->Register(SlowWriteString<UTF8>);
1671-
registry->Register(FastWriteString<ASCII>);
1672-
registry->Register(fast_write_string_ascii.GetTypeInfo());
1673-
registry->Register(FastWriteString<LATIN1>);
1674-
registry->Register(fast_write_string_latin1.GetTypeInfo());
1675-
registry->Register(FastWriteString<UTF8>);
1676-
registry->Register(fast_write_string_utf8.GetTypeInfo());
1667+
registry->Register(fast_write_string_ascii);
1668+
registry->Register(fast_write_string_latin1);
1669+
registry->Register(fast_write_string_utf8);
16771670
registry->Register(StringWrite<ASCII>);
16781671
registry->Register(StringWrite<BASE64>);
16791672
registry->Register(StringWrite<BASE64URL>);

src/node_external_reference.h

Lines changed: 7 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -10,121 +10,13 @@
1010

1111
namespace node {
1212

13-
using CFunctionCallbackWithalueAndOptions = bool (*)(
14-
v8::Local<v8::Value>, v8::Local<v8::Value>, v8::FastApiCallbackOptions&);
15-
using CFunctionCallbackWithMultipleValueAndOptions =
16-
bool (*)(v8::Local<v8::Value>,
17-
v8::Local<v8::Value>,
18-
v8::Local<v8::Value>,
19-
v8::FastApiCallbackOptions&);
20-
using CFunctionA =
21-
uint32_t (*)(v8::Local<v8::Value> receiver,
22-
v8::Local<v8::Value> sourceValue,
23-
// NOLINTNEXTLINE(runtime/references) This is V8 api.
24-
v8::FastApiCallbackOptions& options);
25-
using CFunctionCallbackWithOneByteString =
26-
uint32_t (*)(v8::Local<v8::Value>, const v8::FastOneByteString&);
27-
28-
using CFunctionCallbackReturnBool = bool (*)(v8::Local<v8::Value> unused,
29-
v8::Local<v8::Value> receiver);
30-
using CFunctionCallback = void (*)(v8::Local<v8::Value> unused,
31-
v8::Local<v8::Value> receiver);
32-
using CFunctionCallbackReturnDouble =
33-
double (*)(v8::Local<v8::Object> unused, v8::Local<v8::Object> receiver);
34-
using CFunctionCallbackReturnInt32 =
35-
int32_t (*)(v8::Local<v8::Value> receiver,
36-
v8::Local<v8::Value> input,
37-
// NOLINTNEXTLINE(runtime/references) This is V8 api.
38-
v8::FastApiCallbackOptions& options);
39-
using CFunctionCallbackValueReturnDouble =
40-
double (*)(v8::Local<v8::Value> receiver);
41-
using CFunctionCallbackValueReturnDoubleUnusedReceiver =
42-
double (*)(v8::Local<v8::Value> unused, v8::Local<v8::Value> receiver);
43-
using CFunctionCallbackWithInt64 = void (*)(v8::Local<v8::Object> unused,
44-
v8::Local<v8::Object> receiver,
45-
int64_t);
46-
using CFunctionCallbackWithBool = void (*)(v8::Local<v8::Object> unused,
47-
v8::Local<v8::Object> receiver,
48-
bool);
49-
using CFunctionCallbackWithString =
50-
bool (*)(v8::Local<v8::Value>, const v8::FastOneByteString& input);
51-
using CFunctionCallbackWithStrings =
52-
bool (*)(v8::Local<v8::Value>,
53-
const v8::FastOneByteString& input,
54-
const v8::FastOneByteString& base);
55-
using CFunctionCallbackWithTwoUint8Arrays =
56-
int32_t (*)(v8::Local<v8::Value>,
57-
v8::Local<v8::Value>,
58-
v8::Local<v8::Value>,
59-
v8::FastApiCallbackOptions&);
60-
using CFunctionCallbackWithUint8ArrayUint32Int64Bool =
61-
int32_t (*)(v8::Local<v8::Value>,
62-
v8::Local<v8::Value>,
63-
uint32_t,
64-
int64_t,
65-
bool,
66-
v8::FastApiCallbackOptions&);
67-
using CFunctionWithUint32 = uint32_t (*)(v8::Local<v8::Value>,
68-
const uint32_t input);
69-
using CFunctionWithReturnUint32 = uint32_t (*)(v8::Local<v8::Value>);
70-
using CFunctionWithReturnDouble = double (*)(v8::Local<v8::Value>);
71-
using CFunctionWithDoubleReturnDouble = double (*)(v8::Local<v8::Value>,
72-
v8::Local<v8::Value>,
73-
const double);
74-
using CFunctionWithInt64Fallback = void (*)(v8::Local<v8::Value>,
75-
v8::Local<v8::Value>,
76-
const int64_t,
77-
v8::FastApiCallbackOptions&);
78-
using CFunctionWithBool = void (*)(v8::Local<v8::Value>,
79-
v8::Local<v8::Value>,
80-
bool);
81-
82-
using CFunctionWriteString = uint32_t (*)(v8::Local<v8::Value>,
83-
v8::Local<v8::Value>,
84-
const v8::FastOneByteString&,
85-
uint32_t,
86-
uint32_t,
87-
v8::FastApiCallbackOptions&);
88-
89-
using CFunctionBufferCopy = uint32_t (*)(v8::Local<v8::Value>,
90-
v8::Local<v8::Value>,
91-
v8::Local<v8::Value>,
92-
uint32_t,
93-
uint32_t,
94-
uint32_t,
95-
v8::FastApiCallbackOptions&);
96-
9713
// This class manages the external references from the V8 heap
9814
// to the C++ addresses in Node.js.
9915
class ExternalReferenceRegistry {
10016
public:
10117
ExternalReferenceRegistry();
10218

10319
#define ALLOWED_EXTERNAL_REFERENCE_TYPES(V) \
104-
V(CFunctionA) \
105-
V(CFunctionCallback) \
106-
V(CFunctionCallbackWithalueAndOptions) \
107-
V(CFunctionCallbackWithMultipleValueAndOptions) \
108-
V(CFunctionCallbackWithOneByteString) \
109-
V(CFunctionCallbackReturnBool) \
110-
V(CFunctionCallbackReturnDouble) \
111-
V(CFunctionCallbackReturnInt32) \
112-
V(CFunctionWithReturnUint32) \
113-
V(CFunctionCallbackValueReturnDouble) \
114-
V(CFunctionCallbackValueReturnDoubleUnusedReceiver) \
115-
V(CFunctionCallbackWithInt64) \
116-
V(CFunctionCallbackWithBool) \
117-
V(CFunctionCallbackWithString) \
118-
V(CFunctionCallbackWithStrings) \
119-
V(CFunctionCallbackWithTwoUint8Arrays) \
120-
V(CFunctionCallbackWithUint8ArrayUint32Int64Bool) \
121-
V(CFunctionWithUint32) \
122-
V(CFunctionWithDoubleReturnDouble) \
123-
V(CFunctionWithInt64Fallback) \
124-
V(CFunctionWithBool) \
125-
V(CFunctionBufferCopy) \
126-
V(CFunctionWriteString) \
127-
V(const v8::CFunctionInfo*) \
12820
V(v8::FunctionCallback) \
12921
V(v8::AccessorNameGetterCallback) \
13022
V(v8::AccessorNameSetterCallback) \
@@ -146,6 +38,13 @@ class ExternalReferenceRegistry {
14638
ALLOWED_EXTERNAL_REFERENCE_TYPES(V)
14739
#undef V
14840

41+
// Registers both the underlying function pointer
42+
// and the corresponding CFunctionInfo.
43+
void Register(const v8::CFunction& c_func) {
44+
RegisterT(c_func.GetAddress());
45+
RegisterT(c_func.GetTypeInfo());
46+
}
47+
14948
// This can be called only once.
15049
const std::vector<intptr_t>& external_references();
15150

src/node_os.cc

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -457,20 +457,17 @@ void RegisterExternalReferences(ExternalReferenceRegistry* registry) {
457457
registry->Register(GetLoadAvg);
458458
registry->Register(GetUptime);
459459
registry->Register(GetTotalMemory);
460-
registry->Register(FastGetTotalMemory);
461-
registry->Register(fast_get_total_memory.GetTypeInfo());
460+
registry->Register(fast_get_total_memory);
462461
registry->Register(GetFreeMemory);
463-
registry->Register(FastGetFreeMemory);
464-
registry->Register(fast_get_free_memory.GetTypeInfo());
462+
registry->Register(fast_get_free_memory);
465463
registry->Register(GetCPUInfo);
466464
registry->Register(GetInterfaceAddresses);
467465
registry->Register(GetHomeDirectory);
468466
registry->Register(GetUserInfo);
469467
registry->Register(SetPriority);
470468
registry->Register(GetPriority);
471469
registry->Register(GetAvailableParallelism);
472-
registry->Register(FastGetAvailableParallelism);
473-
registry->Register(fast_get_available_parallelism.GetTypeInfo());
470+
registry->Register(fast_get_available_parallelism);
474471
registry->Register(GetOSInformation);
475472
}
476473

src/node_perf.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -410,8 +410,7 @@ void RegisterExternalReferences(ExternalReferenceRegistry* registry) {
410410
registry->Register(MarkBootstrapComplete);
411411
registry->Register(UvMetricsInfo);
412412
registry->Register(SlowPerformanceNow);
413-
registry->Register(FastPerformanceNow);
414-
registry->Register(fast_performance_now.GetTypeInfo());
413+
registry->Register(fast_performance_now);
415414
HistogramBase::RegisterExternalReferences(registry);
416415
IntervalHistogram::RegisterExternalReferences(registry);
417416
}

src/node_process_methods.cc

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -666,10 +666,8 @@ void BindingData::RegisterExternalReferences(
666666
ExternalReferenceRegistry* registry) {
667667
registry->Register(SlowNumber);
668668
registry->Register(SlowBigInt);
669-
registry->Register(FastNumber);
670-
registry->Register(FastBigInt);
671-
registry->Register(fast_number_.GetTypeInfo());
672-
registry->Register(fast_bigint_.GetTypeInfo());
669+
registry->Register(fast_number_);
670+
registry->Register(fast_bigint_);
673671
}
674672

675673
BindingData* BindingData::FromV8Value(Local<Value> value) {

src/node_types.cc

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -113,18 +113,15 @@ void InitializeTypes(Local<Object> target,
113113
void RegisterTypesExternalReferences(ExternalReferenceRegistry* registry) {
114114
#define V(type) \
115115
registry->Register(Is##type); \
116-
registry->Register(Is##type##FastApi); \
117-
registry->Register(fast_is_##type##_.GetTypeInfo());
116+
registry->Register(fast_is_##type##_);
118117

119118
VALUE_METHOD_MAP(V)
120119
#undef V
121120

122121
registry->Register(IsAnyArrayBuffer);
123-
registry->Register(IsAnyArrayBufferFastApi);
124-
registry->Register(fast_is_any_array_buffer_.GetTypeInfo());
122+
registry->Register(fast_is_any_array_buffer_);
125123
registry->Register(IsBoxedPrimitive);
126-
registry->Register(IsBoxedPrimitiveFastApi);
127-
registry->Register(fast_is_boxed_primitive_.GetTypeInfo());
124+
registry->Register(fast_is_boxed_primitive_);
128125
}
129126
} // namespace node
130127

src/node_url.cc

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -544,11 +544,8 @@ void BindingData::RegisterExternalReferences(
544544
registry->Register(PathToFileURL);
545545
registry->Register(Update);
546546
registry->Register(CanParse);
547-
registry->Register(FastCanParse);
548-
registry->Register(FastCanParseWithBase);
549-
550547
for (const CFunction& method : fast_can_parse_methods_) {
551-
registry->Register(method.GetTypeInfo());
548+
registry->Register(method);
552549
}
553550
}
554551

src/node_util.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -442,8 +442,7 @@ void RegisterExternalReferences(ExternalReferenceRegistry* registry) {
442442
registry->Register(Sleep);
443443
registry->Register(ArrayBufferViewHasBuffer);
444444
registry->Register(GuessHandleType);
445-
registry->Register(FastGuessHandleType);
446-
registry->Register(fast_guess_handle_type_.GetTypeInfo());
445+
registry->Register(fast_guess_handle_type_);
447446
registry->Register(ParseEnv);
448447
registry->Register(IsInsideNodeModules);
449448
registry->Register(DefineLazyProperties);

0 commit comments

Comments
 (0)