3
3
#include " node_errors.h"
4
4
#include " node_external_reference.h"
5
5
#include " util-inl.h"
6
+ #include " util.h"
7
+ #include " v8-fast-api-calls.h"
6
8
7
9
namespace node {
8
10
namespace util {
@@ -12,6 +14,7 @@ using v8::Array;
12
14
using v8::ArrayBufferView;
13
15
using v8::BigInt;
14
16
using v8::Boolean ;
17
+ using v8::CFunction;
15
18
using v8::Context;
16
19
using v8::External;
17
20
using v8::FunctionCallbackInfo;
@@ -317,6 +320,38 @@ static void GuessHandleType(const FunctionCallbackInfo<Value>& args) {
317
320
args.GetReturnValue ().Set (type);
318
321
}
319
322
323
+ static uint32_t FastGuessHandleType (Local<Value> receiver, const uint32_t fd) {
324
+ uv_handle_type t = uv_guess_handle (fd);
325
+ uint32_t type{0 };
326
+
327
+ switch (t) {
328
+ case UV_TCP:
329
+ type = 0 ;
330
+ break ;
331
+ case UV_TTY:
332
+ type = 1 ;
333
+ break ;
334
+ case UV_UDP:
335
+ type = 2 ;
336
+ break ;
337
+ case UV_FILE:
338
+ type = 3 ;
339
+ break ;
340
+ case UV_NAMED_PIPE:
341
+ type = 4 ;
342
+ break ;
343
+ case UV_UNKNOWN_HANDLE:
344
+ type = 5 ;
345
+ break ;
346
+ default :
347
+ ABORT ();
348
+ }
349
+
350
+ return type;
351
+ }
352
+
353
+ CFunction fast_guess_handle_type_ (CFunction::Make(FastGuessHandleType));
354
+
320
355
static void ToUSVString (const FunctionCallbackInfo<Value>& args) {
321
356
Environment* env = Environment::GetCurrent (args);
322
357
CHECK_GE (args.Length (), 2 );
@@ -366,6 +401,8 @@ void RegisterExternalReferences(ExternalReferenceRegistry* registry) {
366
401
registry->Register (WeakReference::IncRef);
367
402
registry->Register (WeakReference::DecRef);
368
403
registry->Register (GuessHandleType);
404
+ registry->Register (FastGuessHandleType);
405
+ registry->Register (fast_guess_handle_type_.GetTypeInfo ());
369
406
registry->Register (ToUSVString);
370
407
}
371
408
@@ -469,7 +506,11 @@ void Initialize(Local<Object> target,
469
506
SetProtoMethod (isolate, weak_ref, " decRef" , WeakReference::DecRef);
470
507
SetConstructorFunction (context, target, " WeakReference" , weak_ref);
471
508
472
- SetMethod (context, target, " guessHandleType" , GuessHandleType);
509
+ SetFastMethodNoSideEffect (context,
510
+ target,
511
+ " guessHandleType" ,
512
+ GuessHandleType,
513
+ &fast_guess_handle_type_);
473
514
474
515
SetMethodNoSideEffect (context, target, " toUSVString" , ToUSVString);
475
516
}
0 commit comments