Skip to content

Commit 617cb58

Browse files
aduh95danielleadams
authored andcommitted
lib: refactor primordials.uncurryThis
This is done to avoid creating an array and gain performance. Co-authored-by: ExE Boss <3889017+ExE-Boss@users.noreply.github.com> PR-URL: #36221 Refs: https://v8.dev/blog/v8-release-80#optimizing-higher-order-builtins Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com>
1 parent 841e8f4 commit 617cb58

File tree

1 file changed

+5
-11
lines changed

1 file changed

+5
-11
lines changed

lib/internal/per_context/primordials.js

+5-11
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,11 @@
1212
// `primordials.Object` where `primordials` is a lexical variable passed
1313
// by the native module compiler.
1414

15-
const ReflectApply = Reflect.apply;
16-
17-
// This function is borrowed from the function with the same name on V8 Extras'
18-
// `utils` object. V8 implements Reflect.apply very efficiently in conjunction
19-
// with the spread syntax, such that no additional special case is needed for
20-
// function calls w/o arguments.
21-
// Refs: https://github.com/v8/v8/blob/d6ead37d265d7215cf9c5f768f279e21bd170212/src/js/prologue.js#L152-L156
22-
function uncurryThis(func) {
23-
return (thisArg, ...args) => ReflectApply(func, thisArg, args);
24-
}
25-
15+
// `uncurryThis` is equivalent to `func => Function.prototype.call.bind(func)`.
16+
// It is using `call.bind(bind, call)` to avoid using `Function.prototype.bind`
17+
// after it may have been mutated by users.
18+
const { bind, call } = Function.prototype;
19+
const uncurryThis = call.bind(bind, call);
2620
primordials.uncurryThis = uncurryThis;
2721

2822
function copyProps(src, dest) {

0 commit comments

Comments
 (0)