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

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

Issue 1390033003: Remove StringImpl::reallocate (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 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
« no previous file with comments | « no previous file | third_party/WebKit/Source/wtf/text/StringImpl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2010 Apple Inc. All rights reserved. 2 * Copyright (C) 2010 Apple Inc. All rights reserved.
3 * Copyright (C) 2012 Google Inc. All rights reserved. 3 * Copyright (C) 2012 Google Inc. All rights reserved.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
7 * are met: 7 * are met:
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 template <> 160 template <>
161 void StringBuilder::reallocateBuffer<LChar>(unsigned requiredLength) 161 void StringBuilder::reallocateBuffer<LChar>(unsigned requiredLength)
162 { 162 {
163 // If the buffer has only one ref (by this StringBuilder), reallocate it, 163 // If the buffer has only one ref (by this StringBuilder), reallocate it,
164 // otherwise fall back to "allocate and copy" method. 164 // otherwise fall back to "allocate and copy" method.
165 m_string = String(); 165 m_string = String();
166 166
167 ASSERT(m_is8Bit); 167 ASSERT(m_is8Bit);
168 ASSERT(m_buffer->is8Bit()); 168 ASSERT(m_buffer->is8Bit());
169 169
170 if (m_buffer->hasOneRef()) { 170 allocateBuffer(m_buffer->characters8(), requiredLength);
171 m_buffer = StringImpl::reallocate(m_buffer.release(), requiredLength);
172 m_bufferCharacters8 = const_cast<LChar*>(m_buffer->characters8());
173 } else {
174 allocateBuffer(m_buffer->characters8(), requiredLength);
175 }
176 } 171 }
177 172
178 template <> 173 template <>
179 void StringBuilder::reallocateBuffer<UChar>(unsigned requiredLength) 174 void StringBuilder::reallocateBuffer<UChar>(unsigned requiredLength)
180 { 175 {
181 // If the buffer has only one ref (by this StringBuilder), reallocate it, 176 // If the buffer has only one ref (by this StringBuilder), reallocate it,
182 // otherwise fall back to "allocate and copy" method. 177 // otherwise fall back to "allocate and copy" method.
183 m_string = String(); 178 m_string = String();
184 179
185 if (m_buffer->is8Bit()) { 180 if (m_buffer->is8Bit())
186 allocateBufferUpConvert(m_buffer->characters8(), requiredLength); 181 allocateBufferUpConvert(m_buffer->characters8(), requiredLength);
187 } else if (m_buffer->hasOneRef()) { 182 else
188 m_buffer = StringImpl::reallocate(m_buffer.release(), requiredLength);
189 m_bufferCharacters16 = const_cast<UChar*>(m_buffer->characters16());
190 } else {
191 allocateBuffer(m_buffer->characters16(), requiredLength); 183 allocateBuffer(m_buffer->characters16(), requiredLength);
192 }
193 } 184 }
194 185
195 void StringBuilder::reserveCapacity(unsigned newCapacity) 186 void StringBuilder::reserveCapacity(unsigned newCapacity)
196 { 187 {
197 if (m_buffer) { 188 if (m_buffer) {
198 // If there is already a buffer, then grow if necessary. 189 // If there is already a buffer, then grow if necessary.
199 if (newCapacity > m_buffer->length()) { 190 if (newCapacity > m_buffer->length()) {
200 if (m_buffer->is8Bit()) 191 if (m_buffer->is8Bit())
201 reallocateBuffer<LChar>(newCapacity); 192 reallocateBuffer<LChar>(newCapacity);
202 else 193 else
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
391 if (!canShrink()) 382 if (!canShrink())
392 return; 383 return;
393 if (m_is8Bit) 384 if (m_is8Bit)
394 reallocateBuffer<LChar>(m_length); 385 reallocateBuffer<LChar>(m_length);
395 else 386 else
396 reallocateBuffer<UChar>(m_length); 387 reallocateBuffer<UChar>(m_length);
397 m_string = m_buffer.release(); 388 m_string = m_buffer.release();
398 } 389 }
399 390
400 } // namespace WTF 391 } // namespace WTF
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/Source/wtf/text/StringImpl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698