Browse Source

LibJS: Add fast path for Int32 values in ToBoolean

It's not uncommon to branch on the boolean value of integers,
so let's do that on the ToBoolean fast path.
Andreas Kling 1 week ago
parent
commit
976ccb9224
1 changed files with 3 additions and 0 deletions
  1. 3 0
      Libraries/LibJS/Runtime/ValueInlines.h

+ 3 - 0
Libraries/LibJS/Runtime/ValueInlines.h

@@ -17,6 +17,9 @@ inline bool Value::to_boolean() const
     if (is_boolean())
         return as_bool();
 
+    if (is_int32())
+        return as_i32() != 0;
+
     return to_boolean_slow_case();
 }