Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1136)

Unified Diff: third_party/WebKit/Source/wtf/text/StringImpl.h

Issue 2585063002: Cache contains only ascii in StringImpl (Closed)
Patch Set: DCHECK + static_Cast Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..6288b563810dad392f1dfec34c1316107237f0a1 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(true),
+ m_needsASCIICheck(false),
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(true),
+ m_needsASCIICheck(false),
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(!length),
+ m_needsASCIICheck(static_cast<bool>(length)),
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(!length),
+ m_needsASCIICheck(static_cast<bool>(length)),
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(!length),
+ m_needsASCIICheck(static_cast<bool>(length)),
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
@@ -475,6 +488,7 @@ class WTF_EXPORT StringImpl {
NEVER_INLINE unsigned hashSlowCase() const;
void destroyIfNotStatic();
+ void updateContainsOnlyASCII() const;
#ifdef STRING_STATS
static StringStats m_stringStats;
@@ -494,6 +508,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 +543,12 @@ 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)
+ updateContainsOnlyASCII();
+ return m_containsOnlyASCII;
+}
+
template <typename CharType>
ALWAYS_INLINE bool equal(const CharType* a,
const CharType* b,
« no previous file with comments | « third_party/WebKit/Source/wtf/text/ASCIIFastPath.h ('k') | third_party/WebKit/Source/wtf/text/StringImpl.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698