Skip to content

Commit fa134dd

Browse files
committedJul 24, 2017
n-api: add fast paths for integer getters
Ref: #14379 PR-URL: #14393 Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Timothy Gu <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Jason Ginchereau <[email protected]>
1 parent 28f0693 commit fa134dd

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
@@ -1822,6 +1822,12 @@ napi_status napi_get_value_int32(napi_env env,
18221822
CHECK_ARG(env, result);
18231823

18241824
v8::Local<v8::Value> val = v8impl::V8LocalValueFromJsValue(value);
1825+
1826+
if (val->IsInt32()) {
1827+
*result = val.As<v8::Int32>()->Value();
1828+
return napi_clear_last_error(env);
1829+
}
1830+
18251831
RETURN_STATUS_IF_FALSE(env, val->IsNumber(), napi_number_expected);
18261832

18271833
v8::Isolate* isolate = env->isolate;
@@ -1841,6 +1847,12 @@ napi_status napi_get_value_uint32(napi_env env,
18411847
CHECK_ARG(env, result);
18421848

18431849
v8::Local<v8::Value> val = v8impl::V8LocalValueFromJsValue(value);
1850+
1851+
if (val->IsUint32()) {
1852+
*result = val.As<v8::Uint32>()->Value();
1853+
return napi_clear_last_error(env);
1854+
}
1855+
18441856
RETURN_STATUS_IF_FALSE(env, val->IsNumber(), napi_number_expected);
18451857

18461858
v8::Isolate* isolate = env->isolate;
@@ -1860,6 +1872,13 @@ napi_status napi_get_value_int64(napi_env env,
18601872
CHECK_ARG(env, result);
18611873

18621874
v8::Local<v8::Value> val = v8impl::V8LocalValueFromJsValue(value);
1875+
1876+
// This is still a fast path very likely to be taken.
1877+
if (val->IsInt32()) {
1878+
*result = val.As<v8::Int32>()->Value();
1879+
return napi_clear_last_error(env);
1880+
}
1881+
18631882
RETURN_STATUS_IF_FALSE(env, val->IsNumber(), napi_number_expected);
18641883

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

0 commit comments

Comments
 (0)
Please sign in to comment.