Skip to content

Commit f4d1cae

Browse files
addaleaxMylesBorins
authored andcommittedApr 16, 2018
n-api: add fast paths for integer getters
Ref: #14379 Backport-PR-URL: #19447 PR-URL: #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>
1 parent 4b9773e commit f4d1cae

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed
 

‎src/node_api.cc

+19
Original file line numberDiff line numberDiff line change
@@ -1912,6 +1912,12 @@ napi_status napi_get_value_int32(napi_env env,
19121912
CHECK_ARG(env, result);
19131913

19141914
v8::Local<v8::Value> val = v8impl::V8LocalValueFromJsValue(value);
1915+
1916+
if (val->IsInt32()) {
1917+
*result = val.As<v8::Int32>()->Value();
1918+
return napi_clear_last_error(env);
1919+
}
1920+
19151921
RETURN_STATUS_IF_FALSE(env, val->IsNumber(), napi_number_expected);
19161922

19171923
v8::Isolate* isolate = env->isolate;
@@ -1931,6 +1937,12 @@ napi_status napi_get_value_uint32(napi_env env,
19311937
CHECK_ARG(env, result);
19321938

19331939
v8::Local<v8::Value> val = v8impl::V8LocalValueFromJsValue(value);
1940+
1941+
if (val->IsUint32()) {
1942+
*result = val.As<v8::Uint32>()->Value();
1943+
return napi_clear_last_error(env);
1944+
}
1945+
19341946
RETURN_STATUS_IF_FALSE(env, val->IsNumber(), napi_number_expected);
19351947

19361948
v8::Isolate* isolate = env->isolate;
@@ -1950,6 +1962,13 @@ napi_status napi_get_value_int64(napi_env env,
19501962
CHECK_ARG(env, result);
19511963

19521964
v8::Local<v8::Value> val = v8impl::V8LocalValueFromJsValue(value);
1965+
1966+
// This is still a fast path very likely to be taken.
1967+
if (val->IsInt32()) {
1968+
*result = val.As<v8::Int32>()->Value();
1969+
return napi_clear_last_error(env);
1970+
}
1971+
19531972
RETURN_STATUS_IF_FALSE(env, val->IsNumber(), napi_number_expected);
19541973

19551974
// v8::Value::IntegerValue() converts NaN to INT64_MIN, inconsistent with

0 commit comments

Comments
 (0)
Please sign in to comment.