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

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

Issue 2016223002: Revert of Replace all occurrences of RELEASE_ASSERT in wtf with CHECK. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Resolve conflict in StringImpl.cpp. Created 4 years, 6 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 * (C) 1999 Lars Knoll (knoll@kde.org) 2 * (C) 1999 Lars Knoll (knoll@kde.org)
3 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2010, 2012 Apple Inc. All rights reserved. 3 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2010, 2012 Apple Inc. All rights reserved.
4 * Copyright (C) 2007-2009 Torch Mobile, Inc. 4 * Copyright (C) 2007-2009 Torch Mobile, Inc.
5 * 5 *
6 * This library is free software; you can redistribute it and/or 6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public 7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either 8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version. 9 * version 2 of the License, or (at your option) any later version.
10 * 10 *
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 return; 85 return;
86 } 86 }
87 87
88 // FIXME: This is extremely inefficient. So much so that we might want to 88 // FIXME: This is extremely inefficient. So much so that we might want to
89 // take this out of String's API. We can make it better by optimizing the 89 // take this out of String's API. We can make it better by optimizing the
90 // case where exactly one String is pointing at this StringImpl, but even 90 // case where exactly one String is pointing at this StringImpl, but even
91 // then it's going to require a call into the allocator every single time. 91 // then it's going to require a call into the allocator every single time.
92 92
93 if (m_impl->is8Bit() && string.m_impl->is8Bit()) { 93 if (m_impl->is8Bit() && string.m_impl->is8Bit()) {
94 LChar* data; 94 LChar* data;
95 CHECK_LE(string.length(), std::numeric_limits<unsigned>::max() - m_impl- >length()); 95 RELEASE_ASSERT(string.length() <= std::numeric_limits<unsigned>::max() - m_impl->length());
96 RefPtr<StringImpl> newImpl = StringImpl::createUninitialized(m_impl->len gth() + string.length(), data); 96 RefPtr<StringImpl> newImpl = StringImpl::createUninitialized(m_impl->len gth() + string.length(), data);
97 memcpy(data, m_impl->characters8(), m_impl->length() * sizeof(LChar)); 97 memcpy(data, m_impl->characters8(), m_impl->length() * sizeof(LChar));
98 memcpy(data + m_impl->length(), string.characters8(), string.length() * sizeof(LChar)); 98 memcpy(data + m_impl->length(), string.characters8(), string.length() * sizeof(LChar));
99 m_impl = newImpl.release(); 99 m_impl = newImpl.release();
100 return; 100 return;
101 } 101 }
102 102
103 UChar* data; 103 UChar* data;
104 CHECK_LE(string.length(), std::numeric_limits<unsigned>::max() - m_impl->len gth()); 104 RELEASE_ASSERT(string.length() <= std::numeric_limits<unsigned>::max() - m_i mpl->length());
105 RefPtr<StringImpl> newImpl = StringImpl::createUninitialized(m_impl->length( ) + string.length(), data); 105 RefPtr<StringImpl> newImpl = StringImpl::createUninitialized(m_impl->length( ) + string.length(), data);
106 106
107 if (m_impl->is8Bit()) 107 if (m_impl->is8Bit())
108 StringImpl::copyChars(data, m_impl->characters8(), m_impl->length()); 108 StringImpl::copyChars(data, m_impl->characters8(), m_impl->length());
109 else 109 else
110 StringImpl::copyChars(data, m_impl->characters16(), m_impl->length()); 110 StringImpl::copyChars(data, m_impl->characters16(), m_impl->length());
111 111
112 if (string.impl()->is8Bit()) 112 if (string.impl()->is8Bit())
113 StringImpl::copyChars(data + m_impl->length(), string.impl()->characters 8(), string.impl()->length()); 113 StringImpl::copyChars(data + m_impl->length(), string.impl()->characters 8(), string.impl()->length());
114 else 114 else
115 StringImpl::copyChars(data + m_impl->length(), string.impl()->characters 16(), string.impl()->length()); 115 StringImpl::copyChars(data + m_impl->length(), string.impl()->characters 16(), string.impl()->length());
116 116
117 m_impl = newImpl.release(); 117 m_impl = newImpl.release();
118 } 118 }
119 119
120 template <typename CharacterType> 120 template <typename CharacterType>
121 inline void String::appendInternal(CharacterType c) 121 inline void String::appendInternal(CharacterType c)
122 { 122 {
123 // FIXME: This is extremely inefficient. So much so that we might want to 123 // FIXME: This is extremely inefficient. So much so that we might want to
124 // take this out of String's API. We can make it better by optimizing the 124 // take this out of String's API. We can make it better by optimizing the
125 // case where exactly one String is pointing at this StringImpl, but even 125 // case where exactly one String is pointing at this StringImpl, but even
126 // then it's going to require a call into the allocator every single time. 126 // then it's going to require a call into the allocator every single time.
127 if (!m_impl) { 127 if (!m_impl) {
128 m_impl = StringImpl::create(&c, 1); 128 m_impl = StringImpl::create(&c, 1);
129 return; 129 return;
130 } 130 }
131 131
132 // FIXME: We should be able to create an 8 bit string via this code path. 132 // FIXME: We should be able to create an 8 bit string via this code path.
133 UChar* data; 133 UChar* data;
134 CHECK_LT(m_impl->length(), std::numeric_limits<unsigned>::max()); 134 RELEASE_ASSERT(m_impl->length() < std::numeric_limits<unsigned>::max());
135 RefPtr<StringImpl> newImpl = StringImpl::createUninitialized(m_impl->length( ) + 1, data); 135 RefPtr<StringImpl> newImpl = StringImpl::createUninitialized(m_impl->length( ) + 1, data);
136 if (m_impl->is8Bit()) 136 if (m_impl->is8Bit())
137 StringImpl::copyChars(data, m_impl->characters8(), m_impl->length()); 137 StringImpl::copyChars(data, m_impl->characters8(), m_impl->length());
138 else 138 else
139 StringImpl::copyChars(data, m_impl->characters16(), m_impl->length()); 139 StringImpl::copyChars(data, m_impl->characters16(), m_impl->length());
140 data[m_impl->length()] = c; 140 data[m_impl->length()] = c;
141 m_impl = newImpl.release(); 141 m_impl = newImpl.release();
142 } 142 }
143 143
144 void String::append(LChar c) 144 void String::append(LChar c)
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 } 187 }
188 188
189 if (!lengthToAppend) 189 if (!lengthToAppend)
190 return; 190 return;
191 191
192 ASSERT(charactersToAppend); 192 ASSERT(charactersToAppend);
193 193
194 unsigned strLength = m_impl->length(); 194 unsigned strLength = m_impl->length();
195 195
196 if (m_impl->is8Bit()) { 196 if (m_impl->is8Bit()) {
197 CHECK_LE(lengthToAppend, std::numeric_limits<unsigned>::max() - strLengt h); 197 RELEASE_ASSERT(lengthToAppend <= std::numeric_limits<unsigned>::max() - strLength);
198 LChar* data; 198 LChar* data;
199 RefPtr<StringImpl> newImpl = StringImpl::createUninitialized(strLength + lengthToAppend, data); 199 RefPtr<StringImpl> newImpl = StringImpl::createUninitialized(strLength + lengthToAppend, data);
200 StringImpl::copyChars(data, m_impl->characters8(), strLength); 200 StringImpl::copyChars(data, m_impl->characters8(), strLength);
201 StringImpl::copyChars(data + strLength, charactersToAppend, lengthToAppe nd); 201 StringImpl::copyChars(data + strLength, charactersToAppend, lengthToAppe nd);
202 m_impl = newImpl.release(); 202 m_impl = newImpl.release();
203 return; 203 return;
204 } 204 }
205 205
206 CHECK_LE(lengthToAppend, std::numeric_limits<unsigned>::max() - strLength); 206 RELEASE_ASSERT(lengthToAppend <= std::numeric_limits<unsigned>::max() - strL ength);
207 UChar* data; 207 UChar* data;
208 RefPtr<StringImpl> newImpl = StringImpl::createUninitialized(length() + leng thToAppend, data); 208 RefPtr<StringImpl> newImpl = StringImpl::createUninitialized(length() + leng thToAppend, data);
209 StringImpl::copyChars(data, m_impl->characters16(), strLength); 209 StringImpl::copyChars(data, m_impl->characters16(), strLength);
210 StringImpl::copyChars(data + strLength, charactersToAppend, lengthToAppend); 210 StringImpl::copyChars(data + strLength, charactersToAppend, lengthToAppend);
211 m_impl = newImpl.release(); 211 m_impl = newImpl.release();
212 } 212 }
213 213
214 void String::append(const UChar* charactersToAppend, unsigned lengthToAppend) 214 void String::append(const UChar* charactersToAppend, unsigned lengthToAppend)
215 { 215 {
216 if (!m_impl) { 216 if (!m_impl) {
217 if (!charactersToAppend) 217 if (!charactersToAppend)
218 return; 218 return;
219 m_impl = StringImpl::create(charactersToAppend, lengthToAppend); 219 m_impl = StringImpl::create(charactersToAppend, lengthToAppend);
220 return; 220 return;
221 } 221 }
222 222
223 if (!lengthToAppend) 223 if (!lengthToAppend)
224 return; 224 return;
225 225
226 unsigned strLength = m_impl->length(); 226 unsigned strLength = m_impl->length();
227 227
228 ASSERT(charactersToAppend); 228 ASSERT(charactersToAppend);
229 CHECK_LE(lengthToAppend, std::numeric_limits<unsigned>::max() - strLength); 229 RELEASE_ASSERT(lengthToAppend <= std::numeric_limits<unsigned>::max() - strL ength);
230 UChar* data; 230 UChar* data;
231 RefPtr<StringImpl> newImpl = StringImpl::createUninitialized(strLength + len gthToAppend, data); 231 RefPtr<StringImpl> newImpl = StringImpl::createUninitialized(strLength + len gthToAppend, data);
232 if (m_impl->is8Bit()) 232 if (m_impl->is8Bit())
233 StringImpl::copyChars(data, characters8(), strLength); 233 StringImpl::copyChars(data, characters8(), strLength);
234 else 234 else
235 StringImpl::copyChars(data, characters16(), strLength); 235 StringImpl::copyChars(data, characters16(), strLength);
236 StringImpl::copyChars(data + strLength, charactersToAppend, lengthToAppend); 236 StringImpl::copyChars(data + strLength, charactersToAppend, lengthToAppend);
237 m_impl = newImpl.release(); 237 m_impl = newImpl.release();
238 } 238 }
239 239
240 template<typename CharType> 240 template<typename CharType>
241 PassRefPtr<StringImpl> insertInternal(PassRefPtr<StringImpl> impl, const CharTyp e* charactersToInsert, unsigned lengthToInsert, unsigned position) 241 PassRefPtr<StringImpl> insertInternal(PassRefPtr<StringImpl> impl, const CharTyp e* charactersToInsert, unsigned lengthToInsert, unsigned position)
242 { 242 {
243 if (!lengthToInsert) 243 if (!lengthToInsert)
244 return impl; 244 return impl;
245 245
246 ASSERT(charactersToInsert); 246 ASSERT(charactersToInsert);
247 UChar* data; // FIXME: We should be able to create an 8 bit string here. 247 UChar* data; // FIXME: We should be able to create an 8 bit string here.
248 CHECK_LE(lengthToInsert, std::numeric_limits<unsigned>::max() - impl->length ()); 248 RELEASE_ASSERT(lengthToInsert <= std::numeric_limits<unsigned>::max() - impl ->length());
249 RefPtr<StringImpl> newImpl = StringImpl::createUninitialized(impl->length() + lengthToInsert, data); 249 RefPtr<StringImpl> newImpl = StringImpl::createUninitialized(impl->length() + lengthToInsert, data);
250 250
251 if (impl->is8Bit()) 251 if (impl->is8Bit())
252 StringImpl::copyChars(data, impl->characters8(), position); 252 StringImpl::copyChars(data, impl->characters8(), position);
253 else 253 else
254 StringImpl::copyChars(data, impl->characters16(), position); 254 StringImpl::copyChars(data, impl->characters16(), position);
255 255
256 StringImpl::copyChars(data + position, charactersToInsert, lengthToInsert); 256 StringImpl::copyChars(data + position, charactersToInsert, lengthToInsert);
257 257
258 if (impl->is8Bit()) 258 if (impl->is8Bit())
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
430 Vector<UChar> result; 430 Vector<UChar> result;
431 result.reserveInitialCapacity(length() + 1); 431 result.reserveInitialCapacity(length() + 1);
432 appendTo(result); 432 appendTo(result);
433 result.append('\0'); 433 result.append('\0');
434 return result; 434 return result;
435 } 435 }
436 436
437 unsigned String::copyTo(UChar* buffer, unsigned pos, unsigned maxLength) const 437 unsigned String::copyTo(UChar* buffer, unsigned pos, unsigned maxLength) const
438 { 438 {
439 unsigned length = this->length(); 439 unsigned length = this->length();
440 CHECK_LE(pos, length); 440 RELEASE_ASSERT(pos <= length);
441 unsigned numCharacters = std::min(length - pos, maxLength); 441 unsigned numCharacters = std::min(length - pos, maxLength);
442 if (!numCharacters) 442 if (!numCharacters)
443 return 0; 443 return 0;
444 if (is8Bit()) 444 if (is8Bit())
445 StringImpl::copyChars(buffer, characters8() + pos, numCharacters); 445 StringImpl::copyChars(buffer, characters8() + pos, numCharacters);
446 else 446 else
447 StringImpl::copyChars(buffer, characters16() + pos, numCharacters); 447 StringImpl::copyChars(buffer, characters16() + pos, numCharacters);
448 return numCharacters; 448 return numCharacters;
449 } 449 }
450 450
(...skipping 418 matching lines...) Expand 10 before | Expand all | Expand 10 after
869 UChar* destination; 869 UChar* destination;
870 String result = String::createUninitialized(length, destination); 870 String result = String::createUninitialized(length, destination);
871 871
872 StringImpl::copyChars(destination, source, length); 872 StringImpl::copyChars(destination, source, length);
873 873
874 return result; 874 return result;
875 } 875 }
876 876
877 String String::fromUTF8(const LChar* stringStart, size_t length) 877 String String::fromUTF8(const LChar* stringStart, size_t length)
878 { 878 {
879 CHECK_LE(length, std::numeric_limits<unsigned>::max()); 879 RELEASE_ASSERT(length <= std::numeric_limits<unsigned>::max());
880 880
881 if (!stringStart) 881 if (!stringStart)
882 return String(); 882 return String();
883 883
884 if (!length) 884 if (!length)
885 return emptyString(); 885 return emptyString();
886 886
887 if (charactersAreAllASCII(stringStart, length)) 887 if (charactersAreAllASCII(stringStart, length))
888 return StringImpl::create(stringStart, length); 888 return StringImpl::create(stringStart, length);
889 889
(...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after
1286 buffer.append('\0'); 1286 buffer.append('\0');
1287 return buffer; 1287 return buffer;
1288 } 1288 }
1289 1289
1290 Vector<char> asciiDebug(String& string) 1290 Vector<char> asciiDebug(String& string)
1291 { 1291 {
1292 return asciiDebug(string.impl()); 1292 return asciiDebug(string.impl());
1293 } 1293 }
1294 1294
1295 #endif 1295 #endif
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/wtf/text/TextCodecUTF16.cpp ('k') | third_party/WebKit/Source/wtf/typed_arrays/ArrayBuffer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698