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

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

Issue 1611343002: wtf reformat test Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: pydent Created 4 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/AtomicString.h
diff --git a/third_party/WebKit/Source/wtf/text/AtomicString.h b/third_party/WebKit/Source/wtf/text/AtomicString.h
index fcc3454ff98f6d22becd31f98e580fffd22d70f9..02e222797abccd4a179cc33b5e081735a9c8bb33 100644
--- a/third_party/WebKit/Source/wtf/text/AtomicString.h
+++ b/third_party/WebKit/Source/wtf/text/AtomicString.h
@@ -34,184 +34,273 @@ namespace WTF {
struct AtomicStringHash;
class WTF_EXPORT AtomicString {
- USING_FAST_MALLOC(AtomicString);
-public:
- static void init();
- static void reserveTableCapacity(size_t);
-
- AtomicString() { }
- AtomicString(const LChar* s) : m_string(add(s)) { }
- AtomicString(const char* s) : m_string(add(s)) { }
- AtomicString(const LChar* s, unsigned length) : m_string(add(s, length)) { }
- AtomicString(const UChar* s, unsigned length) : m_string(add(s, length)) { }
- AtomicString(const UChar* s, unsigned length, unsigned existingHash) : m_string(add(s, length, existingHash)) { }
- AtomicString(const UChar* s) : m_string(add(s)) { }
-
- template<size_t inlineCapacity>
- explicit AtomicString(const Vector<UChar, inlineCapacity>& characters)
- : m_string(add(characters.data(), characters.size()))
- {
- }
-
- // Constructing an AtomicString from a String / StringImpl can be expensive if
- // the StringImpl is not already atomic.
- explicit AtomicString(StringImpl* impl) : m_string(add(impl)) { }
- explicit AtomicString(const String& s) : m_string(add(s.impl())) { }
-
- 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(); }
-
- static StringImpl* find(const StringImpl*);
-
- operator const String&() const { return m_string; }
- const String& string() const { return m_string; }
-
- StringImpl* impl() const { return m_string.impl(); }
-
- bool is8Bit() const { return m_string.is8Bit(); }
- const LChar* characters8() const { return m_string.characters8(); }
- const UChar* characters16() const { return m_string.characters16(); }
- unsigned length() const { return m_string.length(); }
-
- UChar operator[](unsigned i) const { return m_string[i]; }
-
- bool contains(UChar c) const { return m_string.contains(c); }
- bool contains(const LChar* s, TextCaseSensitivity caseSensitivity = TextCaseSensitive) const
- { return m_string.contains(s, caseSensitivity); }
- bool contains(const String& s, TextCaseSensitivity caseSensitivity = TextCaseSensitive) const
- { return m_string.contains(s, caseSensitivity); }
-
- size_t find(UChar c, size_t start = 0) const { return m_string.find(c, start); }
- size_t find(const LChar* s, size_t start = 0, TextCaseSensitivity caseSensitivity = TextCaseSensitive) const
- { return m_string.find(s, start, caseSensitivity); }
- size_t find(const String& s, size_t start = 0, TextCaseSensitivity caseSensitivity = TextCaseSensitive) const
- { return m_string.find(s, start, caseSensitivity); }
-
- bool startsWith(const String& s, TextCaseSensitivity caseSensitivity = TextCaseSensitive) const
- { return m_string.startsWith(s, caseSensitivity); }
- bool startsWith(UChar character) const
- { return m_string.startsWith(character); }
- template<unsigned matchLength>
- bool startsWith(const char (&prefix)[matchLength], TextCaseSensitivity caseSensitivity = TextCaseSensitive) const
- { return m_string.startsWith<matchLength>(prefix, caseSensitivity); }
-
- bool endsWith(const String& s, TextCaseSensitivity caseSensitivity = TextCaseSensitive) const
- { return m_string.endsWith(s, caseSensitivity); }
- bool endsWith(UChar character) const
- { return m_string.endsWith(character); }
- template<unsigned matchLength>
- bool endsWith(const char (&prefix)[matchLength], TextCaseSensitivity caseSensitivity = TextCaseSensitive) const
- { return m_string.endsWith<matchLength>(prefix, caseSensitivity); }
-
- AtomicString lower() const;
- AtomicString lowerASCII() const;
- AtomicString upper() const { return AtomicString(impl()->upper()); }
-
- int toInt(bool* ok = 0) const { return m_string.toInt(ok); }
- double toDouble(bool* ok = 0) const { return m_string.toDouble(ok); }
- float toFloat(bool* ok = 0) const { return m_string.toFloat(ok); }
-
- static AtomicString number(int);
- static AtomicString number(unsigned);
- static AtomicString number(long);
- static AtomicString number(unsigned long);
- static AtomicString number(long long);
- static AtomicString number(unsigned long long);
-
- static AtomicString number(double, unsigned precision = 6, TrailingZerosTruncatingPolicy = TruncateTrailingZeros);
-
- bool isNull() const { return m_string.isNull(); }
- bool isEmpty() const { return m_string.isEmpty(); }
-
- static void remove(StringImpl*);
+ USING_FAST_MALLOC(AtomicString);
+
+ public:
+ static void init();
+ static void reserveTableCapacity(size_t);
+
+ AtomicString() {}
+ AtomicString(const LChar* s) : m_string(add(s)) {}
+ AtomicString(const char* s) : m_string(add(s)) {}
+ AtomicString(const LChar* s, unsigned length) : m_string(add(s, length)) {}
+ AtomicString(const UChar* s, unsigned length) : m_string(add(s, length)) {}
+ AtomicString(const UChar* s, unsigned length, unsigned existingHash)
+ : m_string(add(s, length, existingHash)) {}
+ AtomicString(const UChar* s) : m_string(add(s)) {}
+
+ template <size_t inlineCapacity>
+ explicit AtomicString(const Vector<UChar, inlineCapacity>& characters)
+ : m_string(add(characters.data(), characters.size())) {}
+
+ // Constructing an AtomicString from a String / StringImpl can be expensive if
+ // the StringImpl is not already atomic.
+ explicit AtomicString(StringImpl* impl) : m_string(add(impl)) {}
+ explicit AtomicString(const String& s) : m_string(add(s.impl())) {}
+
+ 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();
+ }
+
+ static StringImpl* find(const StringImpl*);
+
+ operator const String&() const { return m_string; }
+ const String& string() const { return m_string; }
+
+ StringImpl* impl() const { return m_string.impl(); }
+
+ bool is8Bit() const { return m_string.is8Bit(); }
+ const LChar* characters8() const { return m_string.characters8(); }
+ const UChar* characters16() const { return m_string.characters16(); }
+ unsigned length() const { return m_string.length(); }
+
+ UChar operator[](unsigned i) const { return m_string[i]; }
+
+ bool contains(UChar c) const { return m_string.contains(c); }
+ bool contains(const LChar* s,
+ TextCaseSensitivity caseSensitivity = TextCaseSensitive) const {
+ return m_string.contains(s, caseSensitivity);
+ }
+ bool contains(const String& s,
+ TextCaseSensitivity caseSensitivity = TextCaseSensitive) const {
+ return m_string.contains(s, caseSensitivity);
+ }
+
+ size_t find(UChar c, size_t start = 0) const {
+ return m_string.find(c, start);
+ }
+ size_t find(const LChar* s,
+ size_t start = 0,
+ TextCaseSensitivity caseSensitivity = TextCaseSensitive) const {
+ return m_string.find(s, start, caseSensitivity);
+ }
+ size_t find(const String& s,
+ size_t start = 0,
+ TextCaseSensitivity caseSensitivity = TextCaseSensitive) const {
+ return m_string.find(s, start, caseSensitivity);
+ }
+
+ bool startsWith(
+ const String& s,
+ TextCaseSensitivity caseSensitivity = TextCaseSensitive) const {
+ return m_string.startsWith(s, caseSensitivity);
+ }
+ bool startsWith(UChar character) const {
+ return m_string.startsWith(character);
+ }
+ template <unsigned matchLength>
+ bool startsWith(
+ const char (&prefix)[matchLength],
+ TextCaseSensitivity caseSensitivity = TextCaseSensitive) const {
+ return m_string.startsWith<matchLength>(prefix, caseSensitivity);
+ }
+
+ bool endsWith(const String& s,
+ TextCaseSensitivity caseSensitivity = TextCaseSensitive) const {
+ return m_string.endsWith(s, caseSensitivity);
+ }
+ bool endsWith(UChar character) const { return m_string.endsWith(character); }
+ template <unsigned matchLength>
+ bool endsWith(const char (&prefix)[matchLength],
+ TextCaseSensitivity caseSensitivity = TextCaseSensitive) const {
+ return m_string.endsWith<matchLength>(prefix, caseSensitivity);
+ }
+
+ AtomicString lower() const;
+ AtomicString lowerASCII() const;
+ AtomicString upper() const { return AtomicString(impl()->upper()); }
+
+ int toInt(bool* ok = 0) const { return m_string.toInt(ok); }
+ double toDouble(bool* ok = 0) const { return m_string.toDouble(ok); }
+ float toFloat(bool* ok = 0) const { return m_string.toFloat(ok); }
+
+ static AtomicString number(int);
+ static AtomicString number(unsigned);
+ static AtomicString number(long);
+ static AtomicString number(unsigned long);
+ static AtomicString number(long long);
+ static AtomicString number(unsigned long long);
+
+ static AtomicString number(
+ double,
+ unsigned precision = 6,
+ TrailingZerosTruncatingPolicy = TruncateTrailingZeros);
+
+ bool isNull() const { return m_string.isNull(); }
+ bool isEmpty() const { return m_string.isEmpty(); }
+
+ static void remove(StringImpl*);
#ifdef __OBJC__
- AtomicString(NSString* s) : m_string(add((CFStringRef)s)) { }
- operator NSString*() const { return m_string; }
+ AtomicString(NSString* s) : m_string(add((CFStringRef)s)) {}
+ operator NSString*() const { return m_string; }
#endif
- // AtomicString::fromUTF8 will return a null string if
- // the input data contains invalid UTF-8 sequences.
- static AtomicString fromUTF8(const char*, size_t);
- static AtomicString fromUTF8(const char*);
+ // AtomicString::fromUTF8 will return a null string if
+ // the input data contains invalid UTF-8 sequences.
+ static AtomicString fromUTF8(const char*, size_t);
+ static AtomicString fromUTF8(const char*);
- CString ascii() const { return m_string.ascii(); }
- CString latin1() const { return m_string.latin1(); }
- CString utf8(UTF8ConversionMode mode = LenientUTF8Conversion) const { return m_string.utf8(mode); }
+ CString ascii() const { return m_string.ascii(); }
+ CString latin1() const { return m_string.latin1(); }
+ CString utf8(UTF8ConversionMode mode = LenientUTF8Conversion) const {
+ return m_string.utf8(mode);
+ }
#ifndef NDEBUG
- void show() const;
+ void show() const;
#endif
-private:
- String m_string;
-
- static PassRefPtr<StringImpl> add(const LChar*);
- 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);
- ALWAYS_INLINE static PassRefPtr<StringImpl> add(const char* s, unsigned length) { return add(reinterpret_cast<const LChar*>(s), length); }
- static PassRefPtr<StringImpl> add(const UChar*, unsigned length, unsigned existingHash);
- static PassRefPtr<StringImpl> add(const UChar*);
- static PassRefPtr<StringImpl> add(StringImpl*, unsigned offset, unsigned length);
- ALWAYS_INLINE static PassRefPtr<StringImpl> add(StringImpl* r)
- {
- if (!r || r->isAtomic())
- return r;
- return addSlowCase(r);
- }
- static PassRefPtr<StringImpl> addFromLiteralData(const char* characters, unsigned length);
- static PassRefPtr<StringImpl> addSlowCase(StringImpl*);
+ private:
+ String m_string;
+
+ static PassRefPtr<StringImpl> add(const LChar*);
+ 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);
+ ALWAYS_INLINE static PassRefPtr<StringImpl> add(const char* s,
+ unsigned length) {
+ return add(reinterpret_cast<const LChar*>(s), length);
+ }
+ static PassRefPtr<StringImpl> add(const UChar*,
+ unsigned length,
+ unsigned existingHash);
+ static PassRefPtr<StringImpl> add(const UChar*);
+ static PassRefPtr<StringImpl> add(StringImpl*,
+ unsigned offset,
+ unsigned length);
+ ALWAYS_INLINE static PassRefPtr<StringImpl> add(StringImpl* r) {
+ if (!r || r->isAtomic())
+ 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);
+ static PassRefPtr<StringImpl> add(CFStringRef);
#endif
- static AtomicString fromUTF8Internal(const char*, const char*);
+ static AtomicString fromUTF8Internal(const char*, const char*);
};
-inline bool operator==(const AtomicString& a, const AtomicString& b) { return a.impl() == b.impl(); }
+inline bool operator==(const AtomicString& a, const AtomicString& b) {
+ return a.impl() == b.impl();
+}
WTF_EXPORT bool operator==(const AtomicString&, const LChar*);
-inline bool operator==(const AtomicString& a, const char* b) { return WTF::equal(a.impl(), reinterpret_cast<const LChar*>(b)); }
-inline bool operator==(const AtomicString& a, const Vector<UChar>& b) { return a.impl() && equal(a.impl(), b.data(), b.size()); }
-inline bool operator==(const AtomicString& a, const String& b) { return equal(a.impl(), b.impl()); }
-inline bool operator==(const LChar* a, const AtomicString& b) { return b == a; }
-inline bool operator==(const char* a, const AtomicString& b) { return b == a; }
-inline bool operator==(const String& a, const AtomicString& b) { return equal(a.impl(), b.impl()); }
-inline bool operator==(const Vector<UChar>& a, const AtomicString& b) { return b == a; }
-
-inline bool operator!=(const AtomicString& a, const AtomicString& b) { return a.impl() != b.impl(); }
-inline bool operator!=(const AtomicString& a, const LChar* b) { return !(a == b); }
-inline bool operator!=(const AtomicString& a, const char* b) { return !(a == b); }
-inline bool operator!=(const AtomicString& a, const String& b) { return !equal(a.impl(), b.impl()); }
-inline bool operator!=(const AtomicString& a, const Vector<UChar>& b) { return !(a == b); }
-inline bool operator!=(const LChar* a, const AtomicString& b) { return !(b == a); }
-inline bool operator!=(const char* a, const AtomicString& b) { return !(b == a); }
-inline bool operator!=(const String& a, const AtomicString& b) { return !equal(a.impl(), b.impl()); }
-inline bool operator!=(const Vector<UChar>& a, const AtomicString& b) { return !(a == b); }
-
-inline bool equalIgnoringCase(const AtomicString& a, const AtomicString& b) { return equalIgnoringCase(a.impl(), b.impl()); }
-inline bool equalIgnoringCase(const AtomicString& a, const LChar* b) { return equalIgnoringCase(a.impl(), b); }
-inline bool equalIgnoringCase(const AtomicString& a, const char* b) { return equalIgnoringCase(a.impl(), reinterpret_cast<const LChar*>(b)); }
-inline bool equalIgnoringCase(const AtomicString& a, const String& b) { return equalIgnoringCase(a.impl(), b.impl()); }
-inline bool equalIgnoringCase(const LChar* a, const AtomicString& b) { return equalIgnoringCase(a, b.impl()); }
-inline bool equalIgnoringCase(const char* a, const AtomicString& b) { return equalIgnoringCase(reinterpret_cast<const LChar*>(a), b.impl()); }
-inline bool equalIgnoringCase(const String& a, const AtomicString& b) { return equalIgnoringCase(a.impl(), b.impl()); }
+inline bool operator==(const AtomicString& a, const char* b) {
+ return WTF::equal(a.impl(), reinterpret_cast<const LChar*>(b));
+}
+inline bool operator==(const AtomicString& a, const Vector<UChar>& b) {
+ return a.impl() && equal(a.impl(), b.data(), b.size());
+}
+inline bool operator==(const AtomicString& a, const String& b) {
+ return equal(a.impl(), b.impl());
+}
+inline bool operator==(const LChar* a, const AtomicString& b) {
+ return b == a;
+}
+inline bool operator==(const char* a, const AtomicString& b) {
+ return b == a;
+}
+inline bool operator==(const String& a, const AtomicString& b) {
+ return equal(a.impl(), b.impl());
+}
+inline bool operator==(const Vector<UChar>& a, const AtomicString& b) {
+ return b == a;
+}
+
+inline bool operator!=(const AtomicString& a, const AtomicString& b) {
+ return a.impl() != b.impl();
+}
+inline bool operator!=(const AtomicString& a, const LChar* b) {
+ return !(a == b);
+}
+inline bool operator!=(const AtomicString& a, const char* b) {
+ return !(a == b);
+}
+inline bool operator!=(const AtomicString& a, const String& b) {
+ return !equal(a.impl(), b.impl());
+}
+inline bool operator!=(const AtomicString& a, const Vector<UChar>& b) {
+ return !(a == b);
+}
+inline bool operator!=(const LChar* a, const AtomicString& b) {
+ return !(b == a);
+}
+inline bool operator!=(const char* a, const AtomicString& b) {
+ return !(b == a);
+}
+inline bool operator!=(const String& a, const AtomicString& b) {
+ return !equal(a.impl(), b.impl());
+}
+inline bool operator!=(const Vector<UChar>& a, const AtomicString& b) {
+ return !(a == b);
+}
+
+inline bool equalIgnoringCase(const AtomicString& a, const AtomicString& b) {
+ return equalIgnoringCase(a.impl(), b.impl());
+}
+inline bool equalIgnoringCase(const AtomicString& a, const LChar* b) {
+ return equalIgnoringCase(a.impl(), b);
+}
+inline bool equalIgnoringCase(const AtomicString& a, const char* b) {
+ return equalIgnoringCase(a.impl(), reinterpret_cast<const LChar*>(b));
+}
+inline bool equalIgnoringCase(const AtomicString& a, const String& b) {
+ return equalIgnoringCase(a.impl(), b.impl());
+}
+inline bool equalIgnoringCase(const LChar* a, const AtomicString& b) {
+ return equalIgnoringCase(a, b.impl());
+}
+inline bool equalIgnoringCase(const char* a, const AtomicString& b) {
+ return equalIgnoringCase(reinterpret_cast<const LChar*>(a), b.impl());
+}
+inline bool equalIgnoringCase(const String& a, const AtomicString& b) {
+ return equalIgnoringCase(a.impl(), b.impl());
+}
// Define external global variables for the commonly used atomic strings.
// These are only usable from the main thread.
@@ -222,34 +311,36 @@ WTF_EXPORT extern const AtomicString& xmlAtom;
WTF_EXPORT extern const AtomicString& xmlnsAtom;
WTF_EXPORT extern const AtomicString& xlinkAtom;
-inline AtomicString AtomicString::fromUTF8(const char* characters, size_t length)
-{
- if (!characters)
- return nullAtom;
- if (!length)
- return emptyAtom;
- return fromUTF8Internal(characters, characters + length);
+inline AtomicString AtomicString::fromUTF8(const char* characters,
+ size_t length) {
+ if (!characters)
+ return nullAtom;
+ if (!length)
+ return emptyAtom;
+ return fromUTF8Internal(characters, characters + length);
}
-inline AtomicString AtomicString::fromUTF8(const char* characters)
-{
- if (!characters)
- return nullAtom;
- if (!*characters)
- return emptyAtom;
- return fromUTF8Internal(characters, 0);
+inline AtomicString AtomicString::fromUTF8(const char* characters) {
+ if (!characters)
+ return nullAtom;
+ if (!*characters)
+ return emptyAtom;
+ return fromUTF8Internal(characters, 0);
}
// AtomicStringHash is the default hash for AtomicString
-template<typename T> struct DefaultHash;
-template<> struct DefaultHash<AtomicString> {
- typedef AtomicStringHash Hash;
+template <typename T>
+struct DefaultHash;
+template <>
+struct DefaultHash<AtomicString> {
+ typedef AtomicStringHash Hash;
};
// Pretty printer for gtest.
-WTF_UNITTEST_HELPERS_EXPORT std::ostream& operator<<(std::ostream&, const AtomicString&);
+WTF_UNITTEST_HELPERS_EXPORT std::ostream& operator<<(std::ostream&,
+ const AtomicString&);
-} // namespace WTF
+} // namespace WTF
WTF_ALLOW_MOVE_INIT_AND_COMPARE_WITH_MEM_FUNCTIONS(AtomicString);
@@ -262,4 +353,4 @@ using WTF::xmlnsAtom;
using WTF::xlinkAtom;
#include "wtf/text/StringConcatenate.h"
-#endif // AtomicString_h
+#endif // AtomicString_h
« no previous file with comments | « third_party/WebKit/Source/wtf/text/ASCIIFastPath.h ('k') | third_party/WebKit/Source/wtf/text/AtomicString.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698