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

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

Issue 1844223002: Literal AtomicString construction can rely on strlen optimization. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 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 | « third_party/WebKit/Source/web/WebViewImpl.cpp ('k') | third_party/WebKit/Source/wtf/text/AtomicString.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/wtf/text/AtomicString.h
diff --git a/third_party/WebKit/Source/wtf/text/AtomicString.h b/third_party/WebKit/Source/wtf/text/AtomicString.h
index abd6c58b0a7d7d555855180e60ca157404afa97d..9f79d42f60e46ebe422dc713014bb5991d028d70 100644
--- a/third_party/WebKit/Source/wtf/text/AtomicString.h
+++ b/third_party/WebKit/Source/wtf/text/AtomicString.h
@@ -26,6 +26,7 @@
#include "wtf/WTFExport.h"
#include "wtf/text/CString.h"
#include "wtf/text/WTFString.h"
+#include <cstring>
#include <iosfwd>
namespace WTF {
@@ -59,20 +60,6 @@ public:
AtomicString(StringImpl* baseString, unsigned start, unsigned length) : m_string(add(baseString, start, length)) { }
- enum ConstructFromLiteralTag { ConstructFromLiteral };
- AtomicString(const char* characters, unsigned length, ConstructFromLiteralTag)
- : m_string(addFromLiteralData(characters, length))
- {
- }
-
- template<unsigned charactersCount>
- ALWAYS_INLINE AtomicString(const char (&characters)[charactersCount], ConstructFromLiteralTag)
- : m_string(addFromLiteralData(characters, charactersCount - 1))
- {
- static_assert(charactersCount > 1, "AtomicString FromLiteralData should not be empty");
- static_assert((charactersCount - 1 <= ((unsigned(~0) - sizeof(StringImpl)) / sizeof(LChar))), "AtomicString FromLiteralData cannot overflow");
- }
-
// Hash table deleted values, which are only constructed and never copied or destroyed.
AtomicString(WTF::HashTableDeletedValueType) : m_string(WTF::HashTableDeletedValue) { }
bool isHashTableDeletedValue() const { return m_string.isHashTableDeletedValue(); }
@@ -161,7 +148,12 @@ public:
private:
String m_string;
- static PassRefPtr<StringImpl> add(const LChar*);
+ ALWAYS_INLINE static PassRefPtr<StringImpl> add(const LChar* characters)
Yuta Kitamura 2016/03/31 06:12:06 String literals have a type of |const char[N]|, so
esprehn 2016/03/31 18:04:12 Yeah you can do that, but that won't work for con
+ {
+ if (!characters)
dcheng 2016/03/31 05:54:36 null is a valid input to add()?! That sounds insan
esprehn 2016/03/31 18:04:12 I'm just doing what the old code did... I agree it
+ return nullptr;
+ return add(characters, strlen(reinterpret_cast<const char*>(characters)));
+ }
ALWAYS_INLINE static PassRefPtr<StringImpl> add(const char* s) { return add(reinterpret_cast<const LChar*>(s)); }
static PassRefPtr<StringImpl> add(const LChar*, unsigned length);
static PassRefPtr<StringImpl> add(const UChar*, unsigned length);
@@ -175,7 +167,6 @@ private:
return r;
return addSlowCase(r);
}
- static PassRefPtr<StringImpl> addFromLiteralData(const char* characters, unsigned length);
static PassRefPtr<StringImpl> addSlowCase(StringImpl*);
#if OS(MACOSX)
static PassRefPtr<StringImpl> add(CFStringRef);
« no previous file with comments | « third_party/WebKit/Source/web/WebViewImpl.cpp ('k') | third_party/WebKit/Source/wtf/text/AtomicString.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698