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 680b40ab284190f3b24656cf8461501b6548bd23..8e2b18f7b3d60981cf418c151e580532f49f607f 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> |
| @@ -133,6 +134,8 @@ class WTF_EXPORT StringImpl { |
| : m_refCount(1), |
| m_length(0), |
| m_hash(0), |
| + m_containsOnlyASCII(false), |
|
esprehn
2017/01/04 20:30:37
true
Charlie Harrison
2017/01/04 20:53:51
Done.
|
| + m_needsASCIICheck(true), |
|
esprehn
2017/01/04 20:30:37
false
Charlie Harrison
2017/01/04 20:53:51
Done.
|
| m_isAtomic(false), |
| m_is8Bit(true), |
| m_isStatic(true) { |
| @@ -149,6 +152,8 @@ class WTF_EXPORT StringImpl { |
| : m_refCount(1), |
| m_length(0), |
| m_hash(0), |
| + m_containsOnlyASCII(false), |
|
esprehn
2017/01/04 20:30:37
m_containsOnlyASCII(true), the string is empty
Charlie Harrison
2017/01/04 20:53:51
Done.
|
| + m_needsASCIICheck(true), |
|
esprehn
2017/01/04 20:30:37
false
Charlie Harrison
2017/01/04 20:53:50
Done.
|
| m_isAtomic(false), |
| m_is8Bit(false), |
| m_isStatic(true) { |
| @@ -162,6 +167,8 @@ class WTF_EXPORT StringImpl { |
| : m_refCount(1), |
| m_length(length), |
| m_hash(0), |
| + m_containsOnlyASCII(false), |
|
esprehn
2017/01/04 20:30:37
(!length)
Charlie Harrison
2017/01/04 20:53:51
Done.
|
| + m_needsASCIICheck(true), |
|
esprehn
2017/01/04 20:30:37
(length)
Charlie Harrison
2017/01/04 20:53:50
Done.
|
| m_isAtomic(false), |
| m_is8Bit(true), |
| m_isStatic(false) { |
| @@ -173,6 +180,8 @@ class WTF_EXPORT StringImpl { |
| : m_refCount(1), |
| m_length(length), |
| m_hash(0), |
| + m_containsOnlyASCII(false), |
|
esprehn
2017/01/04 20:30:37
(!length)
Charlie Harrison
2017/01/04 20:53:50
Done.
|
| + m_needsASCIICheck(true), |
|
esprehn
2017/01/04 20:30:37
(length)
Charlie Harrison
2017/01/04 20:53:50
Done.
|
| m_isAtomic(false), |
| m_is8Bit(false), |
| m_isStatic(false) { |
| @@ -185,6 +194,8 @@ class WTF_EXPORT StringImpl { |
| : m_refCount(1), |
| m_length(length), |
| m_hash(hash), |
| + m_containsOnlyASCII(false), |
| + m_needsASCIICheck(true), |
|
esprehn
2017/01/04 20:30:37
ditto
Charlie Harrison
2017/01/04 20:53:50
Done.
|
| 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 |
| @@ -494,6 +507,8 @@ class WTF_EXPORT StringImpl { |
| unsigned m_refCount; |
| const unsigned m_length; |
| mutable unsigned m_hash : 24; |
| + mutable unsigned m_containsOnlyASCII : 1; |
| + mutable unsigned m_needsASCIICheck : 1; |
| unsigned m_isAtomic : 1; |
| const unsigned m_is8Bit : 1; |
| const unsigned m_isStatic : 1; |
| @@ -527,6 +542,17 @@ inline bool equal(const char* a, StringImpl* b) { |
| } |
| WTF_EXPORT bool equalNonNull(const StringImpl* a, const StringImpl* b); |
| +ALWAYS_INLINE bool StringImpl::containsOnlyASCII() const { |
| + if (m_needsASCIICheck) { |
| + m_containsOnlyASCII = |
| + !length() || |
|
esprehn
2017/01/04 20:30:37
Strings are immutable, so you don't need the lengt
Charlie Harrison
2017/01/04 20:53:50
Done.
|
| + (is8Bit() ? charactersAreAllASCII(characters8(), length()) |
| + : charactersAreAllASCII(characters16(), length())); |
|
esprehn
2017/01/04 20:30:37
This is inlining a lot of code which I know the ol
Charlie Harrison
2017/01/04 20:53:50
SGTM. Done.
|
| + m_needsASCIICheck = false; |
| + } |
| + return m_containsOnlyASCII; |
| +} |
| + |
| template <typename CharType> |
| ALWAYS_INLINE bool equal(const CharType* a, |
| const CharType* b, |