#ifndef PropertyName_h
#define PropertyName_h
#include "Identifier.h"
#include "PrivateName.h"
namespace JSC {
template <typename CharType>
ALWAYS_INLINE uint32_t toUInt32FromCharacters(const CharType* characters, unsigned length)
{
if (!length)
return UINT_MAX;
uint32_t value = characters[0] - '0';
if (value > 9)
return UINT_MAX;
if (!value && length > 1)
return UINT_MAX;
while (--length) {
if (value > 0xFFFFFFFFU / 10)
return UINT_MAX;
value *= 10;
uint32_t newValue = *(++characters) - '0';
if (newValue > 9)
return UINT_MAX;
newValue += value;
if (newValue < value)
return UINT_MAX;
value = newValue;
}
return value;
}
ALWAYS_INLINE uint32_t toUInt32FromStringImpl(StringImpl* impl)
{
if (impl->is8Bit())
return toUInt32FromCharacters(impl->characters8(), impl->length());
return toUInt32FromCharacters(impl->characters16(), impl->length());
}
class PropertyName {
public:
PropertyName(const Identifier& propertyName)
: m_impl(propertyName.impl())
{
ASSERT(!m_impl || m_impl->isAtomic());
}
PropertyName(const PrivateName& propertyName)
: m_impl(propertyName.uid())
{
ASSERT(m_impl && m_impl->isEmptyUnique());
}
StringImpl* uid() const
{
return m_impl;
}
StringImpl* publicName() const
{
return m_impl->isEmptyUnique() ? 0 : m_impl;
}
static const uint32_t NotAnIndex = UINT_MAX;
uint32_t asIndex()
{
return m_impl ? toUInt32FromStringImpl(m_impl) : NotAnIndex;
}
private:
StringImpl* m_impl;
};
inline bool operator==(PropertyName a, const Identifier& b)
{
return a.uid() == b.impl();
}
inline bool operator==(const Identifier& a, PropertyName b)
{
return a.impl() == b.uid();
}
inline bool operator==(PropertyName a, PropertyName b)
{
return a.uid() == b.uid();
}
inline bool operator!=(PropertyName a, const Identifier& b)
{
return a.uid() != b.impl();
}
inline bool operator!=(const Identifier& a, PropertyName b)
{
return a.impl() != b.uid();
}
inline bool operator!=(PropertyName a, PropertyName b)
{
return a.uid() != b.uid();
}
}
#endif