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

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

Issue 2585063002: Cache contains only ascii in StringImpl (Closed)
Patch Set: reviews Created 3 years, 12 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
« no previous file with comments | « no previous file | third_party/WebKit/Source/wtf/text/WTFString.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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,
« no previous file with comments | « no previous file | third_party/WebKit/Source/wtf/text/WTFString.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698