Changeset 178756 in webkit for trunk/Source/JavaScriptCore/runtime/PropertyName.h
- Timestamp:
- Jan 20, 2015, 2:43:06 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/runtime/PropertyName.h
r178751 r178756 29 29 #include "Identifier.h" 30 30 #include "PrivateName.h" 31 #include <wtf/Optional.h>32 31 33 32 namespace JSC { 34 33 35 34 template <typename CharType> 36 ALWAYS_INLINE Optional<uint32_t>toUInt32FromCharacters(const CharType* characters, unsigned length)35 ALWAYS_INLINE uint32_t toUInt32FromCharacters(const CharType* characters, unsigned length) 37 36 { 38 37 // An empty string is not a number. 39 38 if (!length) 40 return Nullopt;39 return UINT_MAX; 41 40 42 41 // Get the first character, turning it into a digit. 43 42 uint32_t value = characters[0] - '0'; 44 43 if (value > 9) 45 return Nullopt;44 return UINT_MAX; 46 45 47 46 // Check for leading zeros. If the first characher is 0, then the 48 47 // length of the string must be one - e.g. "042" is not equal to "42". 49 48 if (!value && length > 1) 50 return Nullopt;49 return UINT_MAX; 51 50 52 51 while (--length) { 53 52 // Multiply value by 10, checking for overflow out of 32 bits. 54 53 if (value > 0xFFFFFFFFU / 10) 55 return Nullopt;54 return UINT_MAX; 56 55 value *= 10; 57 56 … … 59 58 uint32_t newValue = *(++characters) - '0'; 60 59 if (newValue > 9) 61 return Nullopt;60 return UINT_MAX; 62 61 63 62 // Add in the old value, checking for overflow out of 32 bits. 64 63 newValue += value; 65 64 if (newValue < value) 66 return Nullopt;65 return UINT_MAX; 67 66 value = newValue; 68 67 } 69 70 if (value == UINT_MAX) 71 return Nullopt; 68 72 69 return value; 73 70 } 74 71 75 ALWAYS_INLINE Optional<uint32_t>toUInt32FromStringImpl(StringImpl* impl)72 ALWAYS_INLINE uint32_t toUInt32FromStringImpl(StringImpl* impl) 76 73 { 77 74 if (impl->is8Bit()) … … 113 110 static const uint32_t NotAnIndex = UINT_MAX; 114 111 115 Optional<uint32_t>asIndex()112 uint32_t asIndex() 116 113 { 117 return m_impl ? toUInt32FromStringImpl(m_impl) : N ullopt;114 return m_impl ? toUInt32FromStringImpl(m_impl) : NotAnIndex; 118 115 } 119 116 120 117 void dump(PrintStream& out) const 121 118 {
Note:
See TracChangeset
for help on using the changeset viewer.