mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-30 12:49:19 +00:00
LibJS: Add fast paths in ToNumeric for booleans, null and undefined
These are still in the out-of-line "slow path" for ToNumeric, but skipping all the coercion machinery can save us a lot of time.
This commit is contained in:
parent
3fcef0c519
commit
8de03e8cfd
Notes:
github-actions[bot]
2025-04-03 16:48:52 +00:00
Author: https://github.com/awesomekling
Commit: 8de03e8cfd
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/4208
1 changed files with 11 additions and 0 deletions
|
@ -602,6 +602,17 @@ ThrowCompletionOr<GC::Ref<Object>> Value::to_object(VM& vm) const
|
|||
// 7.1.3 ToNumeric ( value ), https://tc39.es/ecma262/#sec-tonumeric
|
||||
FLATTEN ThrowCompletionOr<Value> Value::to_numeric_slow_case(VM& vm) const
|
||||
{
|
||||
// OPTIMIZATION: Fast paths for some trivial common cases.
|
||||
if (is_boolean()) {
|
||||
return Value(as_bool() ? 1 : 0);
|
||||
}
|
||||
if (is_null()) {
|
||||
return Value(0);
|
||||
}
|
||||
if (is_undefined()) {
|
||||
return js_nan();
|
||||
}
|
||||
|
||||
// 1. Let primValue be ? ToPrimitive(value, number).
|
||||
auto primitive_value = TRY(to_primitive(vm, Value::PreferredType::Number));
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue