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

Side by Side Diff: third_party/WebKit/Source/wtf/text/StringConcatenate.cpp

Issue 2359663002: wtf: Implement StringView specialization of string concatenation. (Closed)
Patch Set: StringImpl::copyChars Created 4 years, 2 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright 2014 The Chromium Authors. All rights reserved. 2 * Copyright 2014 The Chromium Authors. All rights reserved.
3 * Use of this source code is governed by a BSD-style license that can be 3 * Use of this source code is governed by a BSD-style license that can be
4 * found in the LICENSE file. 4 * found in the LICENSE file.
5 */ 5 */
6 6
7 #include "wtf/text/StringConcatenate.h" 7 #include "wtf/text/StringConcatenate.h"
8 8
9 // This macro is helpful for testing how many intermediate Strings are created w hile evaluating an 9 // This macro is helpful for testing how many intermediate Strings are created w hile evaluating an
10 // expression containing operator+. 10 // expression containing operator+.
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 for (size_t i = 0; i < m_buffer.size(); ++i) 111 for (size_t i = 0; i < m_buffer.size(); ++i)
112 destination[i] = m_buffer[i]; 112 destination[i] = m_buffer[i];
113 } 113 }
114 114
115 void WTF::StringTypeAdapter<Vector<LChar>>::writeTo(UChar* destination) 115 void WTF::StringTypeAdapter<Vector<LChar>>::writeTo(UChar* destination)
116 { 116 {
117 for (size_t i = 0; i < m_buffer.size(); ++i) 117 for (size_t i = 0; i < m_buffer.size(); ++i)
118 destination[i] = m_buffer[i]; 118 destination[i] = m_buffer[i];
119 } 119 }
120 120
121 void WTF::StringTypeAdapter<String>::writeTo(LChar* destination) 121 void WTF::StringTypeAdapter<StringView>::writeTo(LChar* destination)
122 { 122 {
123 unsigned length = m_buffer.length(); 123 DCHECK(is8Bit());
124 124 StringImpl::copyChars(destination, m_view.characters8(), m_view.length());
125 ASSERT(is8Bit());
126 const LChar* data = m_buffer.characters8();
127 for (unsigned i = 0; i < length; ++i)
128 destination[i] = data[i];
129
130 WTF_STRINGTYPEADAPTER_COPIED_WTF_STRING(); 125 WTF_STRINGTYPEADAPTER_COPIED_WTF_STRING();
131 } 126 }
132 127
133 void WTF::StringTypeAdapter<String>::writeTo(UChar* destination) 128 void WTF::StringTypeAdapter<StringView>::writeTo(UChar* destination)
134 { 129 {
135 unsigned length = m_buffer.length(); 130 if (is8Bit())
136 131 StringImpl::copyChars(destination, m_view.characters8(), m_view.length() );
137 if (is8Bit()) { 132 else
138 const LChar* data = m_buffer.characters8(); 133 StringImpl::copyChars(destination, m_view.characters16(), m_view.length( ));
139 for (unsigned i = 0; i < length; ++i)
140 destination[i] = data[i];
141 } else {
142 const UChar* data = m_buffer.characters16();
143 for (unsigned i = 0; i < length; ++i)
144 destination[i] = data[i];
145 }
146
147 WTF_STRINGTYPEADAPTER_COPIED_WTF_STRING(); 134 WTF_STRINGTYPEADAPTER_COPIED_WTF_STRING();
148 } 135 }
149
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/wtf/text/StringConcatenate.h ('k') | third_party/WebKit/Source/wtf/text/StringOperators.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698