Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit fa134dd

Browse filesBrowse files
committed
n-api: add fast paths for integer getters
Ref: #14379 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 28f0693 commit fa134dd
Copy full SHA for fa134dd

File tree

Expand file treeCollapse file tree

1 file changed

+19
-0
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+19
-0
lines changed
Open diff view settings
Collapse file

‎src/node_api.cc‎

Copy file name to clipboardExpand all lines: src/node_api.cc
+19Lines changed: 19 additions & 0 deletions
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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.