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

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

Issue 2245773002: Simplify and clean up StringTypeAdaptor and StringAppend. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: const ref it all. Created 4 years, 4 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/wtf/text/StringConcatenate.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/wtf/text/StringOperators.h
diff --git a/third_party/WebKit/Source/wtf/text/StringOperators.h b/third_party/WebKit/Source/wtf/text/StringOperators.h
index 9100cdaad788a75289554b3585206854c3a3b70e..fe01a2aea87a30b421de21149784645fc8017e17 100644
--- a/third_party/WebKit/Source/wtf/text/StringOperators.h
+++ b/third_party/WebKit/Source/wtf/text/StringOperators.h
@@ -31,97 +31,56 @@ template<typename StringType1, typename StringType2>
class StringAppend final {
STACK_ALLOCATED();
public:
- StringAppend(StringType1 string1, StringType2 string2);
+ StringAppend(const StringType1& string1, const StringType2& string2)
+ : m_adapter1(string1)
+ , m_adapter2(string2) {}
- operator String() const;
-
- operator AtomicString() const;
-
- bool is8Bit();
-
- void writeTo(LChar* destination);
+ operator String() const
+ {
+ return String(makeString(m_adapter1, m_adapter2));
+ }
+ operator AtomicString() const
+ {
+ return AtomicString(makeString(m_adapter1, m_adapter2));
+ }
- void writeTo(UChar* destination);
+ unsigned length() const { return m_adapter1.length() + m_adapter2.length(); }
+ bool is8Bit() const { return m_adapter1.is8Bit() && m_adapter2.is8Bit(); }
- unsigned length();
+ void writeTo(LChar* destination) const
+ {
+ DCHECK(is8Bit());
+ m_adapter1.writeTo(destination);
+ m_adapter2.writeTo(destination + m_adapter1.length());
+ }
+ void writeTo(UChar* destination) const
+ {
+ m_adapter1.writeTo(destination);
+ m_adapter2.writeTo(destination + m_adapter1.length());
+ }
private:
- StringType1 m_string1;
- StringType2 m_string2;
+ StringTypeAdapter<StringType1> m_adapter1;
+ StringTypeAdapter<StringType2> m_adapter2;
};
template<typename StringType1, typename StringType2>
-StringAppend<StringType1, StringType2>::StringAppend(StringType1 string1, StringType2 string2)
- : m_string1(string1)
- , m_string2(string2)
-{
-}
-
-template<typename StringType1, typename StringType2>
-StringAppend<StringType1, StringType2>::operator String() const
-{
- return String(makeString(m_string1, m_string2));
-}
-
-template<typename StringType1, typename StringType2>
-StringAppend<StringType1, StringType2>::operator AtomicString() const
-{
- return AtomicString(makeString(m_string1, m_string2));
-}
-
-template<typename StringType1, typename StringType2>
-bool StringAppend<StringType1, StringType2>::is8Bit()
-{
- StringTypeAdapter<StringType1> adapter1(m_string1);
- StringTypeAdapter<StringType2> adapter2(m_string2);
- return adapter1.is8Bit() && adapter2.is8Bit();
-}
-
-template<typename StringType1, typename StringType2>
-void StringAppend<StringType1, StringType2>::writeTo(LChar* destination)
-{
- ASSERT(is8Bit());
- StringTypeAdapter<StringType1> adapter1(m_string1);
- StringTypeAdapter<StringType2> adapter2(m_string2);
- adapter1.writeTo(destination);
- adapter2.writeTo(destination + adapter1.length());
-}
-
-template<typename StringType1, typename StringType2>
-void StringAppend<StringType1, StringType2>::writeTo(UChar* destination)
-{
- StringTypeAdapter<StringType1> adapter1(m_string1);
- StringTypeAdapter<StringType2> adapter2(m_string2);
- adapter1.writeTo(destination);
- adapter2.writeTo(destination + adapter1.length());
-}
-
-template<typename StringType1, typename StringType2>
-unsigned StringAppend<StringType1, StringType2>::length()
-{
- StringTypeAdapter<StringType1> adapter1(m_string1);
- StringTypeAdapter<StringType2> adapter2(m_string2);
- return adapter1.length() + adapter2.length();
-}
-
-template<typename StringType1, typename StringType2>
class StringTypeAdapter<StringAppend<StringType1, StringType2>> {
STACK_ALLOCATED();
public:
- StringTypeAdapter<StringAppend<StringType1, StringType2>>(StringAppend<StringType1, StringType2>& buffer)
+ StringTypeAdapter<StringAppend<StringType1, StringType2>>(const StringAppend<StringType1, StringType2>& buffer)
: m_buffer(buffer)
{
}
- unsigned length() { return m_buffer.length(); }
-
- bool is8Bit() { return m_buffer.is8Bit(); }
+ unsigned length() const { return m_buffer.length(); }
+ bool is8Bit() const { return m_buffer.is8Bit(); }
- void writeTo(LChar* destination) { m_buffer.writeTo(destination); }
- void writeTo(UChar* destination) { m_buffer.writeTo(destination); }
+ void writeTo(LChar* destination) const { m_buffer.writeTo(destination); }
+ void writeTo(UChar* destination) const { m_buffer.writeTo(destination); }
private:
- StringAppend<StringType1, StringType2>& m_buffer;
+ const StringAppend<StringType1, StringType2>& m_buffer;
};
inline StringAppend<const char*, String> operator+(const char* string1, const String& string2)
« no previous file with comments | « third_party/WebKit/Source/wtf/text/StringConcatenate.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698