OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2010 Apple Inc. All rights reserved. | 2 * Copyright (C) 2010 Apple Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
(...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
362 bool threadSafeMatch(const QualifiedName& a, const QualifiedName& b) | 362 bool threadSafeMatch(const QualifiedName& a, const QualifiedName& b) |
363 { | 363 { |
364 return threadSafeEqual(a.localName().impl(), b.localName().impl()); | 364 return threadSafeEqual(a.localName().impl(), b.localName().impl()); |
365 } | 365 } |
366 | 366 |
367 bool threadSafeMatch(const String& localName, const QualifiedName& qName) | 367 bool threadSafeMatch(const String& localName, const QualifiedName& qName) |
368 { | 368 { |
369 return threadSafeEqual(localName.impl(), qName.localName().impl()); | 369 return threadSafeEqual(localName.impl(), qName.localName().impl()); |
370 } | 370 } |
371 | 371 |
372 StringImpl* findStringIfStatic(const UChar* characters, unsigned length) | 372 template<typename CharType> |
| 373 inline StringImpl* findStringIfStatic(const CharType* characters, unsigned lengt
h) |
373 { | 374 { |
374 // We don't need to try hashing if we know the string is too long. | 375 // We don't need to try hashing if we know the string is too long. |
375 if (length > StringImpl::highestStaticStringLength()) | 376 if (length > StringImpl::highestStaticStringLength()) |
376 return 0; | 377 return 0; |
377 // computeHashAndMaskTop8Bits is the function StringImpl::hash() uses. | 378 // computeHashAndMaskTop8Bits is the function StringImpl::hash() uses. |
378 unsigned hash = StringHasher::computeHashAndMaskTop8Bits(characters, length)
; | 379 unsigned hash = StringHasher::computeHashAndMaskTop8Bits(characters, length)
; |
379 const WTF::StaticStringsTable& table = StringImpl::allStaticStrings(); | 380 const WTF::StaticStringsTable& table = StringImpl::allStaticStrings(); |
380 ASSERT(!table.isEmpty()); | 381 ASSERT(!table.isEmpty()); |
381 | 382 |
382 WTF::StaticStringsTable::const_iterator it = table.find(hash); | 383 WTF::StaticStringsTable::const_iterator it = table.find(hash); |
383 if (it == table.end()) | 384 if (it == table.end()) |
384 return 0; | 385 return 0; |
385 // It's possible to have hash collisions between arbitrary strings and | 386 // It's possible to have hash collisions between arbitrary strings and |
386 // known identifiers (e.g. "bvvfg" collides with "script"). | 387 // known identifiers (e.g. "bvvfg" collides with "script"). |
387 // However ASSERTs in StringImpl::createStatic guard against there ever bein
g collisions | 388 // However ASSERTs in StringImpl::createStatic guard against there ever bein
g collisions |
388 // between static strings. | 389 // between static strings. |
389 if (!equal(it->value, characters, length)) | 390 if (!equal(it->value, characters, length)) |
390 return 0; | 391 return 0; |
391 return it->value; | 392 return it->value; |
392 } | 393 } |
393 | 394 |
| 395 String attemptStaticStringCreation(const LChar* characters, size_t size) |
| 396 { |
| 397 String string(findStringIfStatic(characters, size)); |
| 398 if (string.impl()) |
| 399 return string; |
| 400 return String(characters, size); |
394 } | 401 } |
| 402 |
| 403 String attemptStaticStringCreation(const UChar* characters, size_t size, Charact
erWidth width) |
| 404 { |
| 405 String string(findStringIfStatic(characters, size)); |
| 406 if (string.impl()) |
| 407 return string; |
| 408 if (width == Likely8Bit) |
| 409 string = StringImpl::create8BitIfPossible(characters, size); |
| 410 else if (width == Force8Bit) |
| 411 string = String::make8BitFrom16BitSource(characters, size); |
| 412 else |
| 413 string = String(characters, size); |
| 414 |
| 415 return string; |
| 416 } |
| 417 |
| 418 } |
OLD | NEW |