LibJS: Avoid unnecessary shifts in Value empty/null/undefined checks

We know that the payload is always 0 for these three Value types, and so
we can implement checking for them as full 64-bit compares against
constant values instead of checking just the tag.

This avoids shifting the tag 48 bits to the right before comparing it.
Since these are used all over the place, it actually leads to a nice
code size reduction.
This commit is contained in:
Andreas Kling 2025-04-06 02:08:39 +02:00
parent ae5d37a65d
commit 5c4e611751

View file

@ -95,9 +95,9 @@ public:
[[nodiscard]] u16 tag() const { return m_value.tag; }
bool is_special_empty_value() const { return m_value.tag == EMPTY_TAG; }
bool is_undefined() const { return m_value.tag == UNDEFINED_TAG; }
bool is_null() const { return m_value.tag == NULL_TAG; }
bool is_special_empty_value() const { return m_value.encoded == (EMPTY_TAG << GC::TAG_SHIFT); }
bool is_undefined() const { return m_value.encoded == (UNDEFINED_TAG << GC::TAG_SHIFT); }
bool is_null() const { return m_value.encoded == (NULL_TAG << GC::TAG_SHIFT); }
bool is_number() const { return is_double() || is_int32(); }
bool is_string() const { return m_value.tag == STRING_TAG; }
bool is_object() const { return m_value.tag == OBJECT_TAG; }