Skip to content

Commit 5770181

Browse files
committed
src: implement util.types fast API calls
All util.types.is##Type() calls are ported to the fast API. This improves the performance for multiple APIs such as: - util.inspect (and util.format and console methods respectively) - util.isDeepStrictEqual - assert.(not)deepEqual (including strict and partial mode) It will also improve any other API where these APIs are used.
1 parent 8456a12 commit 5770181

File tree

1 file changed

+43
-5
lines changed

1 file changed

+43
-5
lines changed

src/node_types.cc

Lines changed: 43 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include "node.h"
33
#include "node_external_reference.h"
44

5+
using v8::CFunction;
56
using v8::Context;
67
using v8::FunctionCallbackInfo;
78
using v8::Local;
@@ -42,7 +43,11 @@ namespace {
4243
#define V(type) \
4344
static void Is##type(const FunctionCallbackInfo<Value>& args) { \
4445
args.GetReturnValue().Set(args[0]->Is##type()); \
45-
}
46+
} \
47+
static bool Is##type##FastApi(Local<Value> unused, Local<Value> receiver) { \
48+
return receiver->Is##type(); \
49+
} \
50+
static CFunction fast_is_##type##_ = CFunction::Make(Is##type##FastApi);
4651

4752
VALUE_METHOD_MAP(V)
4853
#undef V
@@ -52,6 +57,14 @@ static void IsAnyArrayBuffer(const FunctionCallbackInfo<Value>& args) {
5257
args[0]->IsArrayBuffer() || args[0]->IsSharedArrayBuffer());
5358
}
5459

60+
static bool IsAnyArrayBufferFastApi(Local<Value> unused,
61+
Local<Value> receiver) {
62+
return receiver->IsArrayBuffer() || receiver->IsSharedArrayBuffer();
63+
}
64+
65+
static CFunction fast_is_any_array_buffer_ =
66+
CFunction::Make(IsAnyArrayBufferFastApi);
67+
5568
static void IsBoxedPrimitive(const FunctionCallbackInfo<Value>& args) {
5669
args.GetReturnValue().Set(
5770
args[0]->IsNumberObject() ||
@@ -61,27 +74,52 @@ static void IsBoxedPrimitive(const FunctionCallbackInfo<Value>& args) {
6174
args[0]->IsSymbolObject());
6275
}
6376

77+
static bool IsBoxedPrimitiveFastApi(Local<Value> unused,
78+
Local<Value> receiver) {
79+
return receiver->IsNumberObject() ||
80+
receiver->IsStringObject() ||
81+
receiver->IsBooleanObject() ||
82+
receiver->IsBigIntObject() ||
83+
receiver->IsSymbolObject();
84+
}
85+
86+
static CFunction fast_is_boxed_primitive_ =
87+
CFunction::Make(IsBoxedPrimitiveFastApi);
88+
6489
void InitializeTypes(Local<Object> target,
6590
Local<Value> unused,
6691
Local<Context> context,
6792
void* priv) {
68-
#define V(type) SetMethodNoSideEffect(context, target, "is" #type, Is##type);
93+
#define V(type) \
94+
SetFastMethodNoSideEffect(context, target, "is" #type, \
95+
Is##type, &fast_is_##type##_);
96+
6997
VALUE_METHOD_MAP(V)
7098
#undef V
7199

72-
SetMethodNoSideEffect(context, target, "isAnyArrayBuffer", IsAnyArrayBuffer);
73-
SetMethodNoSideEffect(context, target, "isBoxedPrimitive", IsBoxedPrimitive);
100+
SetFastMethodNoSideEffect(context, target, "isAnyArrayBuffer",
101+
IsAnyArrayBuffer, &fast_is_any_array_buffer_);
102+
SetFastMethodNoSideEffect(context, target, "isBoxedPrimitive",
103+
IsBoxedPrimitive, &fast_is_boxed_primitive_);
74104
}
75105

76106
} // anonymous namespace
77107

78108
void RegisterTypesExternalReferences(ExternalReferenceRegistry* registry) {
79-
#define V(type) registry->Register(Is##type);
109+
#define V(type) \
110+
registry->Register(Is##type); \
111+
registry->Register(Is##type##FastApi); \
112+
registry->Register(fast_is_##type##_.GetTypeInfo());
113+
80114
VALUE_METHOD_MAP(V)
81115
#undef V
82116

83117
registry->Register(IsAnyArrayBuffer);
118+
registry->Register(IsAnyArrayBufferFastApi);
119+
registry->Register(fast_is_any_array_buffer_.GetTypeInfo());
84120
registry->Register(IsBoxedPrimitive);
121+
registry->Register(IsBoxedPrimitiveFastApi);
122+
registry->Register(fast_is_boxed_primitive_.GetTypeInfo());
85123
}
86124
} // namespace node
87125

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy