Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Port to node-addon-api (and N-API) and remove NAN, libuv, and v8 #2235

Merged
merged 3 commits into from
Sep 19, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
optimize checkArgs
this makes the lineTo benchmark (lineTo executes a very small
number of operations, so it mostly measures the js<->C++ barrier)
run about 50% faster
chearon committed Sep 19, 2023
commit cc840a83cc0ba2692f887d689ca5db04b0446b47
22 changes: 19 additions & 3 deletions src/CanvasRenderingContext2d.cc
Original file line number Diff line number Diff line change
@@ -45,12 +45,28 @@ constexpr double twoPi = M_PI * 2.;
pango_context_get_language(pango_layout_get_context(LAYOUT)))

inline static bool checkArgs(const Napi::CallbackInfo&info, double *args, int argsNum, int offset = 0){
Napi::Number zero = Napi::Number::New(info.Env(), 0);
int argsEnd = offset + argsNum;
Napi::Env env = info.Env();
int argsEnd = std::min(9, offset + argsNum);
bool areArgsValid = true;

napi_value argv[9];
size_t argc = 9;
napi_get_cb_info(env, static_cast<napi_callback_info>(info), &argc, argv, nullptr, nullptr);

for (int i = offset; i < argsEnd; i++) {
double val = info[i].ToNumber().UnwrapOr(zero).DoubleValue();
napi_valuetype type;
double val = 0;

napi_typeof(env, argv[i], &type);
if (type == napi_number) {
// fast path
napi_get_value_double(env, argv[i], &val);
} else {
napi_value num;
if (napi_coerce_to_number(env, argv[i], &num) == napi_ok) {
napi_get_value_double(env, num, &val);
}
}

if (areArgsValid) {
if (!std::isfinite(val)) {