Chromium Code Reviews| Index: third_party/WebKit/Source/wtf/text/StringImpl.h |
| diff --git a/third_party/WebKit/Source/wtf/text/StringImpl.h b/third_party/WebKit/Source/wtf/text/StringImpl.h |
| index 394033874017541a94a96406b2d171769cc1f4f4..a4fbfac7d0b05463fdce0b6b0f9c55bd3b0e5214 100644 |
| --- a/third_party/WebKit/Source/wtf/text/StringImpl.h |
| +++ b/third_party/WebKit/Source/wtf/text/StringImpl.h |
| @@ -30,6 +30,7 @@ |
| #include "wtf/StringHasher.h" |
| #include "wtf/Vector.h" |
| #include "wtf/WTFExport.h" |
| +#include "wtf/text/ASCIIFastPath.h" |
| #include "wtf/text/Unicode.h" |
| #include <limits.h> |
| #include <string.h> |
| @@ -119,6 +120,11 @@ class WTF_EXPORT StringImpl { |
| WTF_MAKE_NONCOPYABLE(StringImpl); |
| private: |
| + enum ContainsASCIIFlag { |
| + DoesNotContainOnlyASCII = 0, |
| + ContainsOnlyASCII = 1, |
| + NotCalculated = 2, |
| + }; |
| // StringImpls are allocated out of the WTF buffer partition. |
| void* operator new(size_t); |
| void* operator new(size_t, void* ptr) { return ptr; } |
| @@ -133,6 +139,7 @@ class WTF_EXPORT StringImpl { |
| : m_refCount(1), |
| m_length(0), |
| m_hash(0), |
| + m_containsOnlyASCII(NotCalculated), |
| m_isAtomic(false), |
| m_is8Bit(true), |
| m_isStatic(true) { |
| @@ -149,6 +156,7 @@ class WTF_EXPORT StringImpl { |
| : m_refCount(1), |
| m_length(0), |
| m_hash(0), |
| + m_containsOnlyASCII(NotCalculated), |
| m_isAtomic(false), |
| m_is8Bit(false), |
| m_isStatic(true) { |
| @@ -162,6 +170,7 @@ class WTF_EXPORT StringImpl { |
| : m_refCount(1), |
| m_length(length), |
| m_hash(0), |
| + m_containsOnlyASCII(NotCalculated), |
| m_isAtomic(false), |
| m_is8Bit(true), |
| m_isStatic(false) { |
| @@ -173,6 +182,7 @@ class WTF_EXPORT StringImpl { |
| : m_refCount(1), |
| m_length(length), |
| m_hash(0), |
| + m_containsOnlyASCII(NotCalculated), |
| m_isAtomic(false), |
| m_is8Bit(false), |
| m_isStatic(false) { |
| @@ -185,6 +195,7 @@ class WTF_EXPORT StringImpl { |
| : m_refCount(1), |
| m_length(length), |
| m_hash(hash), |
| + m_containsOnlyASCII(NotCalculated), |
| m_isAtomic(false), |
| m_is8Bit(true), |
| m_isStatic(true) {} |
| @@ -253,6 +264,8 @@ class WTF_EXPORT StringImpl { |
| bool isStatic() const { return m_isStatic; } |
| + bool containsOnlyASCII() const; |
| + |
| bool isSafeToSendToAnotherThread() const; |
| // The high bits of 'hash' are always empty, but we prefer to store our |
| @@ -498,6 +511,8 @@ class WTF_EXPORT StringImpl { |
| unsigned m_refCount; |
| const unsigned m_length; |
| mutable unsigned m_hash : 24; |
| + // Tristate enum set lazily on calls to containsOnlyASCII. |
| + mutable unsigned m_containsOnlyASCII : 2; |
| unsigned m_isAtomic : 1; |
| const unsigned m_is8Bit : 1; |
| const unsigned m_isStatic : 1; |
| @@ -531,6 +546,16 @@ inline bool equal(const char* a, StringImpl* b) { |
| } |
| WTF_EXPORT bool equalNonNull(const StringImpl* a, const StringImpl* b); |
| +inline bool StringImpl::containsOnlyASCII() const { |
| + if (m_containsOnlyASCII == NotCalculated) { |
| + m_containsOnlyASCII = |
| + !length() || |
| + (is8Bit() ? charactersAreAllASCII(characters8(), length()) |
| + : charactersAreAllASCII(characters16(), length())); |
|
kinuko
2016/12/26 07:32:19
I'd defer the judgement to esprehn (so you might w
|
| + } |
| + return m_containsOnlyASCII; |
| +} |
| + |
| template <typename CharType> |
| ALWAYS_INLINE bool equal(const CharType* a, |
| const CharType* b, |