mirror of
https://github.com/nodejs/node.git
synced 2026-11-29 14:27:57 -05:00
n-api: add fast paths for integer getters
Ref: https://github.com/nodejs/node/issues/14379 PR-URL: https://github.com/nodejs/node/pull/14393 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Timothy Gu <timothygu99@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Jason Ginchereau <jasongin@microsoft.com>
This commit is contained in:
1 file changed
+19
@@ -1909,6 +1909,12 @@ napi_status napi_get_value_int32(napi_env env,
|
||||
CHECK_ARG(env, result);
|
||||
|
||||
v8::Local<v8::Value> val = v8impl::V8LocalValueFromJsValue(value);
|
||||
|
||||
if (val->IsInt32()) {
|
||||
*result = val.As<v8::Int32>()->Value();
|
||||
return napi_clear_last_error(env);
|
||||
}
|
||||
|
||||
RETURN_STATUS_IF_FALSE(env, val->IsNumber(), napi_number_expected);
|
||||
|
||||
v8::Isolate* isolate = env->isolate;
|
||||
@@ -1928,6 +1934,12 @@ napi_status napi_get_value_uint32(napi_env env,
|
||||
CHECK_ARG(env, result);
|
||||
|
||||
v8::Local<v8::Value> val = v8impl::V8LocalValueFromJsValue(value);
|
||||
|
||||
if (val->IsUint32()) {
|
||||
*result = val.As<v8::Uint32>()->Value();
|
||||
return napi_clear_last_error(env);
|
||||
}
|
||||
|
||||
RETURN_STATUS_IF_FALSE(env, val->IsNumber(), napi_number_expected);
|
||||
|
||||
v8::Isolate* isolate = env->isolate;
|
||||
@@ -1947,6 +1959,13 @@ napi_status napi_get_value_int64(napi_env env,
|
||||
CHECK_ARG(env, result);
|
||||
|
||||
v8::Local<v8::Value> val = v8impl::V8LocalValueFromJsValue(value);
|
||||
|
||||
// This is still a fast path very likely to be taken.
|
||||
if (val->IsInt32()) {
|
||||
*result = val.As<v8::Int32>()->Value();
|
||||
return napi_clear_last_error(env);
|
||||
}
|
||||
|
||||
RETURN_STATUS_IF_FALSE(env, val->IsNumber(), napi_number_expected);
|
||||
|
||||
// v8::Value::IntegerValue() converts NaN to INT64_MIN, inconsistent with
|
||||
|
||||
Reference in new issue
Block a user