5
5
#include " node_external_reference.h"
6
6
#include " node_i18n.h"
7
7
#include " util-inl.h"
8
+ #include " v8-fast-api-calls.h"
8
9
#include " v8.h"
9
10
10
11
#include < cstdint>
14
15
namespace node {
15
16
namespace url {
16
17
18
+ using v8::CFunction;
17
19
using v8::Context;
20
+ using v8::FastOneByteString;
18
21
using v8::FunctionCallbackInfo;
19
22
using v8::HandleScope;
20
23
using v8::Isolate;
@@ -113,7 +116,6 @@ void BindingData::DomainToUnicode(const FunctionCallbackInfo<Value>& args) {
113
116
.ToLocalChecked ());
114
117
}
115
118
116
- // TODO(@anonrig): Add V8 Fast API for CanParse method
117
119
void BindingData::CanParse (const FunctionCallbackInfo<Value>& args) {
118
120
CHECK_GE (args.Length (), 1 );
119
121
CHECK (args[0 ]->IsString ()); // input
@@ -140,6 +142,17 @@ void BindingData::CanParse(const FunctionCallbackInfo<Value>& args) {
140
142
args.GetReturnValue ().Set (out.has_value ());
141
143
}
142
144
145
+ bool BindingData::FastCanParse (Local<Value> receiver,
146
+ const FastOneByteString& input) {
147
+ std::string_view input_view (input.data , input.length );
148
+
149
+ auto output = ada::parse<ada::url_aggregator>(input_view);
150
+
151
+ return output.has_value ();
152
+ }
153
+
154
+ CFunction BindingData::fast_can_parse_ (CFunction::Make(FastCanParse));
155
+
143
156
void BindingData::Format (const FunctionCallbackInfo<Value>& args) {
144
157
CHECK_GT (args.Length (), 4 );
145
158
CHECK (args[0 ]->IsString ()); // url href
@@ -320,20 +333,23 @@ void BindingData::Initialize(Local<Object> target,
320
333
321
334
SetMethodNoSideEffect (context, target, " domainToASCII" , DomainToASCII);
322
335
SetMethodNoSideEffect (context, target, " domainToUnicode" , DomainToUnicode);
323
- SetMethodNoSideEffect (context, target, " canParse" , CanParse);
324
336
SetMethodNoSideEffect (context, target, " format" , Format);
325
337
SetMethod (context, target, " parse" , Parse);
326
338
SetMethod (context, target, " update" , Update);
339
+ SetFastMethodNoSideEffect (
340
+ context, target, " canParse" , CanParse, &fast_can_parse_);
327
341
}
328
342
329
343
void BindingData::RegisterExternalReferences (
330
344
ExternalReferenceRegistry* registry) {
331
345
registry->Register (DomainToASCII);
332
346
registry->Register (DomainToUnicode);
333
- registry->Register (CanParse);
334
347
registry->Register (Format);
335
348
registry->Register (Parse);
336
349
registry->Register (Update);
350
+ registry->Register (CanParse);
351
+ registry->Register (FastCanParse);
352
+ registry->Register (fast_can_parse_.GetTypeInfo ());
337
353
}
338
354
339
355
std::string FromFilePath (const std::string_view file_path) {
0 commit comments