OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2013 Apple Inc. All rights reserv
ed. | 2 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2013 Apple Inc. All rights reserv
ed. |
3 * Copyright (C) 2010 Patrick Gansterer <paroga@paroga.com> | 3 * Copyright (C) 2010 Patrick Gansterer <paroga@paroga.com> |
4 * Copyright (C) 2012 Google Inc. All rights reserved. | 4 * Copyright (C) 2012 Google Inc. All rights reserved. |
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 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 { | 135 { |
136 location = StringImpl::create(c).leakRef(); | 136 location = StringImpl::create(c).leakRef(); |
137 location->setHash(hash); | 137 location->setHash(hash); |
138 location->setIsAtomic(true); | 138 location->setIsAtomic(true); |
139 } | 139 } |
140 }; | 140 }; |
141 | 141 |
142 PassRefPtr<StringImpl> AtomicString::add(const LChar* c) | 142 PassRefPtr<StringImpl> AtomicString::add(const LChar* c) |
143 { | 143 { |
144 if (!c) | 144 if (!c) |
145 return 0; | 145 return nullptr; |
146 if (!*c) | 146 if (!*c) |
147 return StringImpl::empty(); | 147 return StringImpl::empty(); |
148 | 148 |
149 return addToStringTable<const LChar*, CStringTranslator>(c); | 149 return addToStringTable<const LChar*, CStringTranslator>(c); |
150 } | 150 } |
151 | 151 |
152 template<typename CharacterType> | 152 template<typename CharacterType> |
153 struct HashTranslatorCharBuffer { | 153 struct HashTranslatorCharBuffer { |
154 const CharacterType* s; | 154 const CharacterType* s; |
155 unsigned length; | 155 unsigned length; |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
269 | 269 |
270 location = newString.release().leakRef(); | 270 location = newString.release().leakRef(); |
271 location->setHash(hash); | 271 location->setHash(hash); |
272 location->setIsAtomic(true); | 272 location->setIsAtomic(true); |
273 } | 273 } |
274 }; | 274 }; |
275 | 275 |
276 PassRefPtr<StringImpl> AtomicString::add(const UChar* s, unsigned length) | 276 PassRefPtr<StringImpl> AtomicString::add(const UChar* s, unsigned length) |
277 { | 277 { |
278 if (!s) | 278 if (!s) |
279 return 0; | 279 return nullptr; |
280 | 280 |
281 if (!length) | 281 if (!length) |
282 return StringImpl::empty(); | 282 return StringImpl::empty(); |
283 | 283 |
284 UCharBuffer buffer = { s, length }; | 284 UCharBuffer buffer = { s, length }; |
285 return addToStringTable<UCharBuffer, UCharBufferTranslator>(buffer); | 285 return addToStringTable<UCharBuffer, UCharBufferTranslator>(buffer); |
286 } | 286 } |
287 | 287 |
288 PassRefPtr<StringImpl> AtomicString::add(const UChar* s, unsigned length, unsign
ed existingHash) | 288 PassRefPtr<StringImpl> AtomicString::add(const UChar* s, unsigned length, unsign
ed existingHash) |
289 { | 289 { |
290 ASSERT(s); | 290 ASSERT(s); |
291 ASSERT(existingHash); | 291 ASSERT(existingHash); |
292 | 292 |
293 if (!length) | 293 if (!length) |
294 return StringImpl::empty(); | 294 return StringImpl::empty(); |
295 | 295 |
296 HashAndCharacters<UChar> buffer = { existingHash, s, length }; | 296 HashAndCharacters<UChar> buffer = { existingHash, s, length }; |
297 return addToStringTable<HashAndCharacters<UChar>, HashAndCharactersTranslato
r<UChar> >(buffer); | 297 return addToStringTable<HashAndCharacters<UChar>, HashAndCharactersTranslato
r<UChar> >(buffer); |
298 } | 298 } |
299 | 299 |
300 PassRefPtr<StringImpl> AtomicString::add(const UChar* s) | 300 PassRefPtr<StringImpl> AtomicString::add(const UChar* s) |
301 { | 301 { |
302 if (!s) | 302 if (!s) |
303 return 0; | 303 return nullptr; |
304 | 304 |
305 unsigned length = 0; | 305 unsigned length = 0; |
306 while (s[length] != UChar(0)) | 306 while (s[length] != UChar(0)) |
307 ++length; | 307 ++length; |
308 | 308 |
309 if (!length) | 309 if (!length) |
310 return StringImpl::empty(); | 310 return StringImpl::empty(); |
311 | 311 |
312 UCharBuffer buffer = { s, length }; | 312 UCharBuffer buffer = { s, length }; |
313 return addToStringTable<UCharBuffer, UCharBufferTranslator>(buffer); | 313 return addToStringTable<UCharBuffer, UCharBufferTranslator>(buffer); |
(...skipping 24 matching lines...) Expand all Loading... |
338 { | 338 { |
339 location = buffer.baseString->substring(buffer.start, buffer.length).lea
kRef(); | 339 location = buffer.baseString->substring(buffer.start, buffer.length).lea
kRef(); |
340 location->setHash(hash); | 340 location->setHash(hash); |
341 location->setIsAtomic(true); | 341 location->setIsAtomic(true); |
342 } | 342 } |
343 }; | 343 }; |
344 | 344 |
345 PassRefPtr<StringImpl> AtomicString::add(StringImpl* baseString, unsigned start,
unsigned length) | 345 PassRefPtr<StringImpl> AtomicString::add(StringImpl* baseString, unsigned start,
unsigned length) |
346 { | 346 { |
347 if (!baseString) | 347 if (!baseString) |
348 return 0; | 348 return nullptr; |
349 | 349 |
350 if (!length || start >= baseString->length()) | 350 if (!length || start >= baseString->length()) |
351 return StringImpl::empty(); | 351 return StringImpl::empty(); |
352 | 352 |
353 unsigned maxLength = baseString->length() - start; | 353 unsigned maxLength = baseString->length() - start; |
354 if (length >= maxLength) { | 354 if (length >= maxLength) { |
355 if (!start) | 355 if (!start) |
356 return add(baseString); | 356 return add(baseString); |
357 length = maxLength; | 357 length = maxLength; |
358 } | 358 } |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
397 { | 397 { |
398 location = StringImpl::create(buf.s, buf.length).leakRef(); | 398 location = StringImpl::create(buf.s, buf.length).leakRef(); |
399 location->setHash(hash); | 399 location->setHash(hash); |
400 location->setIsAtomic(true); | 400 location->setIsAtomic(true); |
401 } | 401 } |
402 }; | 402 }; |
403 | 403 |
404 PassRefPtr<StringImpl> AtomicString::add(const LChar* s, unsigned length) | 404 PassRefPtr<StringImpl> AtomicString::add(const LChar* s, unsigned length) |
405 { | 405 { |
406 if (!s) | 406 if (!s) |
407 return 0; | 407 return nullptr; |
408 | 408 |
409 if (!length) | 409 if (!length) |
410 return StringImpl::empty(); | 410 return StringImpl::empty(); |
411 | 411 |
412 LCharBuffer buffer = { s, length }; | 412 LCharBuffer buffer = { s, length }; |
413 return addToStringTable<LCharBuffer, LCharBufferTranslator>(buffer); | 413 return addToStringTable<LCharBuffer, LCharBufferTranslator>(buffer); |
414 } | 414 } |
415 | 415 |
416 PassRefPtr<StringImpl> AtomicString::addFromLiteralData(const char* characters,
unsigned length) | 416 PassRefPtr<StringImpl> AtomicString::addFromLiteralData(const char* characters,
unsigned length) |
417 { | 417 { |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
526 } | 526 } |
527 | 527 |
528 #ifndef NDEBUG | 528 #ifndef NDEBUG |
529 void AtomicString::show() const | 529 void AtomicString::show() const |
530 { | 530 { |
531 m_string.show(); | 531 m_string.show(); |
532 } | 532 } |
533 #endif | 533 #endif |
534 | 534 |
535 } // namespace WTF | 535 } // namespace WTF |
OLD | NEW |