LibJS: Convert PropertyName and StringOrSymbol to east-const style

This commit is contained in:
Andreas Kling 2021-06-13 11:49:24 +02:00
parent b458090d14
commit 240d2f88d3
2 changed files with 20 additions and 20 deletions

View file

@ -43,20 +43,20 @@ public:
VERIFY(index >= 0); VERIFY(index >= 0);
} }
PropertyName(const char* chars) PropertyName(char const* chars)
: m_type(Type::String) : m_type(Type::String)
, m_string(FlyString(chars)) , m_string(FlyString(chars))
{ {
} }
PropertyName(const String& string) PropertyName(String const& string)
: m_type(Type::String) : m_type(Type::String)
, m_string(FlyString(string)) , m_string(FlyString(string))
{ {
VERIFY(!string.is_null()); VERIFY(!string.is_null());
} }
PropertyName(const FlyString& string) PropertyName(FlyString const& string)
: m_type(Type::String) : m_type(Type::String)
, m_string(string) , m_string(string)
{ {
@ -70,7 +70,7 @@ public:
VERIFY(symbol); VERIFY(symbol);
} }
PropertyName(const StringOrSymbol& string_or_symbol) PropertyName(StringOrSymbol const& string_or_symbol)
{ {
if (string_or_symbol.is_string()) { if (string_or_symbol.is_string()) {
m_string = string_or_symbol.as_string(); m_string = string_or_symbol.as_string();
@ -92,13 +92,13 @@ public:
return m_number; return m_number;
} }
const FlyString& as_string() const FlyString const& as_string() const
{ {
VERIFY(is_string()); VERIFY(is_string());
return m_string; return m_string;
} }
const Symbol* as_symbol() const Symbol const* as_symbol() const
{ {
VERIFY(is_symbol()); VERIFY(is_symbol());
return m_symbol; return m_symbol;

View file

@ -17,19 +17,19 @@ class StringOrSymbol {
public: public:
StringOrSymbol() = default; StringOrSymbol() = default;
StringOrSymbol(const char* chars) StringOrSymbol(char const* chars)
: m_ptr(StringImpl::create(chars).leak_ref()) : m_ptr(StringImpl::create(chars).leak_ref())
{ {
} }
StringOrSymbol(const String& string) StringOrSymbol(String const& string)
: m_ptr(string.impl()) : m_ptr(string.impl())
{ {
VERIFY(!string.is_null()); VERIFY(!string.is_null());
as_string_impl().ref(); as_string_impl().ref();
} }
StringOrSymbol(const FlyString& string) StringOrSymbol(FlyString const& string)
: m_ptr(string.impl()) : m_ptr(string.impl())
{ {
VERIFY(!string.is_null()); VERIFY(!string.is_null());
@ -42,13 +42,13 @@ public:
as_string_impl().unref(); as_string_impl().unref();
} }
StringOrSymbol(const Symbol* symbol) StringOrSymbol(Symbol const* symbol)
: m_ptr(symbol) : m_ptr(symbol)
{ {
set_symbol_flag(); set_symbol_flag();
} }
StringOrSymbol(const StringOrSymbol& other) StringOrSymbol(StringOrSymbol const& other)
{ {
m_ptr = other.m_ptr; m_ptr = other.m_ptr;
if (is_string()) if (is_string())
@ -70,10 +70,10 @@ public:
return as_string_impl(); return as_string_impl();
} }
ALWAYS_INLINE const Symbol* as_symbol() const ALWAYS_INLINE Symbol const* as_symbol() const
{ {
VERIFY(is_symbol()); VERIFY(is_symbol());
return reinterpret_cast<const Symbol*>(bits() & ~1ul); return reinterpret_cast<Symbol const*>(bits() & ~1ul);
} }
String to_display_string() const String to_display_string() const
@ -100,7 +100,7 @@ public:
visitor.visit(const_cast<Symbol*>(as_symbol())); visitor.visit(const_cast<Symbol*>(as_symbol()));
} }
ALWAYS_INLINE bool operator==(const StringOrSymbol& other) const ALWAYS_INLINE bool operator==(StringOrSymbol const& other) const
{ {
if (is_string()) if (is_string())
return other.is_string() && as_string_impl() == other.as_string_impl(); return other.is_string() && as_string_impl() == other.as_string_impl();
@ -109,7 +109,7 @@ public:
return true; return true;
} }
StringOrSymbol& operator=(const StringOrSymbol& other) StringOrSymbol& operator=(StringOrSymbol const& other)
{ {
if (this == &other) if (this == &other)
return *this; return *this;
@ -141,23 +141,23 @@ private:
ALWAYS_INLINE void set_symbol_flag() ALWAYS_INLINE void set_symbol_flag()
{ {
m_ptr = reinterpret_cast<const void*>(bits() | 1ul); m_ptr = reinterpret_cast<void const*>(bits() | 1ul);
} }
ALWAYS_INLINE const StringImpl& as_string_impl() const ALWAYS_INLINE StringImpl const& as_string_impl() const
{ {
VERIFY(is_string()); VERIFY(is_string());
return *reinterpret_cast<const StringImpl*>(m_ptr); return *reinterpret_cast<StringImpl const*>(m_ptr);
} }
const void* m_ptr { nullptr }; void const* m_ptr { nullptr };
}; };
} }
template<> template<>
struct AK::Traits<JS::StringOrSymbol> : public GenericTraits<JS::StringOrSymbol> { struct AK::Traits<JS::StringOrSymbol> : public GenericTraits<JS::StringOrSymbol> {
static unsigned hash(const JS::StringOrSymbol& key) static unsigned hash(JS::StringOrSymbol const& key)
{ {
return key.hash(); return key.hash();
} }