mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-10-19 15:43:20 +00:00
LibJS: Avoid function call if @@hasInstance is default implementation
This makes the instanceof operator signficantly faster by avoiding a generic function call to @@hasInstance unless it has been overridden. 1.15x speed-up on Octane/earley-boyer.js
This commit is contained in:
parent
5a7b0a07cb
commit
0e4450f4b3
Notes:
github-actions[bot]
2025-10-13 15:18:08 +00:00
Author: https://github.com/awesomekling
Commit: 0e4450f4b3
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/6463
5 changed files with 12 additions and 1 deletions
|
@ -2172,6 +2172,12 @@ ThrowCompletionOr<Value> instance_of(VM& vm, Value value, Value target)
|
|||
|
||||
// 3. If instOfHandler is not undefined, then
|
||||
if (instance_of_handler) {
|
||||
// OPTIMIZATION: If the handler is the default OrdinaryHasInstance, we can skip doing a generic call.
|
||||
if (auto* native_function = as_if<NativeFunction>(*instance_of_handler)) {
|
||||
if (native_function->builtin() == Bytecode::Builtin::OrdinaryHasInstance) {
|
||||
return ordinary_has_instance(vm, value, target);
|
||||
}
|
||||
}
|
||||
// a. Return ToBoolean(? Call(instOfHandler, target, « V »)).
|
||||
return Value(TRY(call(vm, *instance_of_handler, target, value)).to_boolean());
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue