]>
git.saurik.com Git - apple/javascriptcore.git/blob - runtime/PropertyName.h
7d2464b4449264b4313f05ed6021d5a462694900
2 * Copyright (C) 2012 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23 * THE POSSIBILITY OF SUCH DAMAGE.
26 #ifndef PropertyName_h
27 #define PropertyName_h
29 #include "Identifier.h"
30 #include "PrivateName.h"
34 template <typename CharType
>
35 ALWAYS_INLINE
uint32_t toUInt32FromCharacters(const CharType
* characters
, unsigned length
)
37 // An empty string is not a number.
41 // Get the first character, turning it into a digit.
42 uint32_t value
= characters
[0] - '0';
46 // Check for leading zeros. If the first characher is 0, then the
47 // length of the string must be one - e.g. "042" is not equal to "42".
48 if (!value
&& length
> 1)
52 // Multiply value by 10, checking for overflow out of 32 bits.
53 if (value
> 0xFFFFFFFFU
/ 10)
57 // Get the next character, turning it into a digit.
58 uint32_t newValue
= *(++characters
) - '0';
62 // Add in the old value, checking for overflow out of 32 bits.
72 ALWAYS_INLINE
uint32_t toUInt32FromStringImpl(StringImpl
* impl
)
75 return toUInt32FromCharacters(impl
->characters8(), impl
->length());
76 return toUInt32FromCharacters(impl
->characters16(), impl
->length());
81 PropertyName(const Identifier
& propertyName
)
82 : m_impl(propertyName
.impl())
84 ASSERT(!m_impl
|| m_impl
->isAtomic());
87 PropertyName(const PrivateName
& propertyName
)
88 : m_impl(propertyName
.uid())
90 ASSERT(m_impl
&& m_impl
->isEmptyUnique());
93 StringImpl
* uid() const
98 StringImpl
* publicName() const
100 return m_impl
->isEmptyUnique() ? 0 : m_impl
;
103 static const uint32_t NotAnIndex
= UINT_MAX
;
107 return m_impl
? toUInt32FromStringImpl(m_impl
) : NotAnIndex
;
114 inline bool operator==(PropertyName a
, const Identifier
& b
)
116 return a
.uid() == b
.impl();
119 inline bool operator==(const Identifier
& a
, PropertyName b
)
121 return a
.impl() == b
.uid();
124 inline bool operator==(PropertyName a
, PropertyName b
)
126 return a
.uid() == b
.uid();
129 inline bool operator!=(PropertyName a
, const Identifier
& b
)
131 return a
.uid() != b
.impl();
134 inline bool operator!=(const Identifier
& a
, PropertyName b
)
136 return a
.impl() != b
.uid();
139 inline bool operator!=(PropertyName a
, PropertyName b
)
141 return a
.uid() != b
.uid();