Skip to content

Commit e5b0dfa

Browse files
Jungku LeeRafaelGSS
Jungku Lee
authored andcommitted
src: remove redundant code for uv_handle_type
PR-URL: #49061 Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Darshan Sen <[email protected]> Reviewed-By: Gerhard Stöbich <[email protected]> Reviewed-By: Deokjin Kim <[email protected]>
1 parent 3d942d9 commit e5b0dfa

File tree

1 file changed

+18
-48
lines changed

1 file changed

+18
-48
lines changed

src/node_util.cc

+18-48
Original file line numberDiff line numberDiff line change
@@ -284,74 +284,44 @@ void WeakReference::DecRef(const FunctionCallbackInfo<Value>& args) {
284284
v8::Number::New(args.GetIsolate(), weak_ref->reference_count_));
285285
}
286286

287-
static void GuessHandleType(const FunctionCallbackInfo<Value>& args) {
288-
Environment* env = Environment::GetCurrent(args);
289-
int fd;
290-
if (!args[0]->Int32Value(env->context()).To(&fd)) return;
291-
CHECK_GE(fd, 0);
292-
293-
uv_handle_type t = uv_guess_handle(fd);
287+
static uint32_t GetUVHandleTypeCode(const uv_handle_type type) {
294288
// TODO(anonrig): We can use an enum here and then create the array in the
295289
// binding, which will remove the hard-coding in C++ and JS land.
296-
uint32_t type{0};
297290

298291
// Currently, the return type of this function corresponds to the index of the
299292
// array defined in the JS land. This is done as an optimization to reduce the
300293
// string serialization overhead.
301-
switch (t) {
294+
switch (type) {
302295
case UV_TCP:
303-
type = 0;
304-
break;
296+
return 0;
305297
case UV_TTY:
306-
type = 1;
307-
break;
298+
return 1;
308299
case UV_UDP:
309-
type = 2;
310-
break;
300+
return 2;
311301
case UV_FILE:
312-
type = 3;
313-
break;
302+
return 3;
314303
case UV_NAMED_PIPE:
315-
type = 4;
316-
break;
304+
return 4;
317305
case UV_UNKNOWN_HANDLE:
318-
type = 5;
319-
break;
306+
return 5;
320307
default:
321308
ABORT();
322309
}
310+
}
311+
312+
static void GuessHandleType(const FunctionCallbackInfo<Value>& args) {
313+
Environment* env = Environment::GetCurrent(args);
314+
int fd;
315+
if (!args[0]->Int32Value(env->context()).To(&fd)) return;
316+
CHECK_GE(fd, 0);
323317

324-
args.GetReturnValue().Set(type);
318+
uv_handle_type t = uv_guess_handle(fd);
319+
args.GetReturnValue().Set(GetUVHandleTypeCode(t));
325320
}
326321

327322
static uint32_t FastGuessHandleType(Local<Value> receiver, const uint32_t fd) {
328323
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;
324+
return GetUVHandleTypeCode(t);
355325
}
356326

357327
CFunction fast_guess_handle_type_(CFunction::Make(FastGuessHandleType));

0 commit comments

Comments
 (0)