3
3
#include " node_errors.h"
4
4
#include " node_external_reference.h"
5
5
#include " util-inl.h"
6
+ #include " v8-fast-api-calls.h"
6
7
7
8
namespace node {
8
9
namespace util {
@@ -12,6 +13,7 @@ using v8::Array;
12
13
using v8::ArrayBufferView;
13
14
using v8::BigInt;
14
15
using v8::Boolean ;
16
+ using v8::CFunction;
15
17
using v8::Context;
16
18
using v8::External;
17
19
using v8::FunctionCallbackInfo;
@@ -322,6 +324,38 @@ static void GuessHandleType(const FunctionCallbackInfo<Value>& args) {
322
324
args.GetReturnValue ().Set (type);
323
325
}
324
326
327
+ static uint32_t FastGuessHandleType (Local<Value> receiver, const uint32_t fd) {
328
+ uv_handle_type t = uv_guess_handle (fd);
329
+ uint32_t type{0 };
330
+
331
+ switch (t) {
332
+ case UV_TCP:
333
+ type = 0 ;
334
+ break ;
335
+ case UV_TTY:
336
+ type = 1 ;
337
+ break ;
338
+ case UV_UDP:
339
+ type = 2 ;
340
+ break ;
341
+ case UV_FILE:
342
+ type = 3 ;
343
+ break ;
344
+ case UV_NAMED_PIPE:
345
+ type = 4 ;
346
+ break ;
347
+ case UV_UNKNOWN_HANDLE:
348
+ type = 5 ;
349
+ break ;
350
+ default :
351
+ ABORT ();
352
+ }
353
+
354
+ return type;
355
+ }
356
+
357
+ CFunction fast_guess_handle_type_ (CFunction::Make(FastGuessHandleType));
358
+
325
359
static void ToUSVString (const FunctionCallbackInfo<Value>& args) {
326
360
Environment* env = Environment::GetCurrent (args);
327
361
CHECK_GE (args.Length (), 2 );
@@ -371,6 +405,8 @@ void RegisterExternalReferences(ExternalReferenceRegistry* registry) {
371
405
registry->Register (WeakReference::IncRef);
372
406
registry->Register (WeakReference::DecRef);
373
407
registry->Register (GuessHandleType);
408
+ registry->Register (FastGuessHandleType);
409
+ registry->Register (fast_guess_handle_type_.GetTypeInfo ());
374
410
registry->Register (ToUSVString);
375
411
}
376
412
@@ -474,7 +510,11 @@ void Initialize(Local<Object> target,
474
510
SetProtoMethod (isolate, weak_ref, " decRef" , WeakReference::DecRef);
475
511
SetConstructorFunction (context, target, " WeakReference" , weak_ref);
476
512
477
- SetMethod (context, target, " guessHandleType" , GuessHandleType);
513
+ SetFastMethodNoSideEffect (context,
514
+ target,
515
+ " guessHandleType" ,
516
+ GuessHandleType,
517
+ &fast_guess_handle_type_);
478
518
479
519
SetMethodNoSideEffect (context, target, " toUSVString" , ToUSVString);
480
520
}
0 commit comments