src: remove redundant code for uv_handle_type

PR-URL: https://github.com/nodejs/node/pull/49061
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Darshan Sen <raisinten@gmail.com>
Reviewed-By: Gerhard Stöbich <deb2001-github@yahoo.de>
Reviewed-By: Deokjin Kim <deokjin81.kim@gmail.com>
This commit is contained in:
Jungku Lee authored and RafaelGSS committed 2023-08-17 08:35:59 -03:00
1 parent 3d942d9842
commit e5b0dfa359
1 file changed
+27 -57
+27 -57
View File
@@ -284,6 +284,31 @@ void WeakReference::DecRef(const FunctionCallbackInfo<Value>& args) {
v8::Number::New(args.GetIsolate(), weak_ref->reference_count_));
}
static uint32_t GetUVHandleTypeCode(const uv_handle_type type) {
// TODO(anonrig): We can use an enum here and then create the array in the
// binding, which will remove the hard-coding in C++ and JS land.
// Currently, the return type of this function corresponds to the index of the
// array defined in the JS land. This is done as an optimization to reduce the
// string serialization overhead.
switch (type) {
case UV_TCP:
return 0;
case UV_TTY:
return 1;
case UV_UDP:
return 2;
case UV_FILE:
return 3;
case UV_NAMED_PIPE:
return 4;
case UV_UNKNOWN_HANDLE:
return 5;
default:
ABORT();
}
}
static void GuessHandleType(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args);
int fd;
@@ -291,67 +316,12 @@ static void GuessHandleType(const FunctionCallbackInfo<Value>& args) {
CHECK_GE(fd, 0);
uv_handle_type t = uv_guess_handle(fd);
// TODO(anonrig): We can use an enum here and then create the array in the
// binding, which will remove the hard-coding in C++ and JS land.
uint32_t type{0};
// Currently, the return type of this function corresponds to the index of the
// array defined in the JS land. This is done as an optimization to reduce the
// string serialization overhead.
switch (t) {
case UV_TCP:
type = 0;
break;
case UV_TTY:
type = 1;
break;
case UV_UDP:
type = 2;
break;
case UV_FILE:
type = 3;
break;
case UV_NAMED_PIPE:
type = 4;
break;
case UV_UNKNOWN_HANDLE:
type = 5;
break;
default:
ABORT();
}
args.GetReturnValue().Set(type);
args.GetReturnValue().Set(GetUVHandleTypeCode(t));
}
static uint32_t FastGuessHandleType(Local<Value> receiver, const uint32_t fd) {
uv_handle_type t = uv_guess_handle(fd);
uint32_t type{0};
switch (t) {
case UV_TCP:
type = 0;
break;
case UV_TTY:
type = 1;
break;
case UV_UDP:
type = 2;
break;
case UV_FILE:
type = 3;
break;
case UV_NAMED_PIPE:
type = 4;
break;
case UV_UNKNOWN_HANDLE:
type = 5;
break;
default:
ABORT();
}
return type;
return GetUVHandleTypeCode(t);
}
CFunction fast_guess_handle_type_(CFunction::Make(FastGuessHandleType));