LibJS: Inline the fast path of Value::to_i32() and simplify to_u32()

The fast path of to_i32() can be neatly inlined everywhere, and we still
have to_i32_slow_case() for non-trivial conversions.

For to_u32(), it really can just be implemented as a static cast to i32!
This commit is contained in:
Andreas Kling 2025-04-09 12:29:53 +02:00 committed by Andreas Kling
commit 938b1e91fe
Notes: github-actions[bot] 2025-04-09 20:07:48 +00:00
9 changed files with 22 additions and 36 deletions

View file

@ -48,4 +48,19 @@ inline ThrowCompletionOr<Value> Value::to_primitive(VM& vm, PreferredType prefer
return to_primitive_slow_case(vm, preferred_type);
}
// 7.1.6 ToInt32 ( argument ), https://tc39.es/ecma262/#sec-toint32
inline ThrowCompletionOr<i32> Value::to_i32(VM& vm) const
{
if (is_int32())
return as_i32();
return to_i32_slow_case(vm);
}
// 7.1.7 ToUint32 ( argument ), https://tc39.es/ecma262/#sec-touint32
inline ThrowCompletionOr<u32> Value::to_u32(VM& vm) const
{
return static_cast<u32>(TRY(to_i32(vm)));
}
}