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 356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
367 bool threadSafeMatch(const QualifiedName& a, const QualifiedName& b) | 367 bool threadSafeMatch(const QualifiedName& a, const QualifiedName& b) |
368 { | 368 { |
369 return threadSafeEqual(a.localName().impl(), b.localName().impl()); | 369 return threadSafeEqual(a.localName().impl(), b.localName().impl()); |
370 } | 370 } |
371 | 371 |
372 bool threadSafeMatch(const String& localName, const QualifiedName& qName) | 372 bool threadSafeMatch(const String& localName, const QualifiedName& qName) |
373 { | 373 { |
374 return threadSafeEqual(localName.impl(), qName.localName().impl()); | 374 return threadSafeEqual(localName.impl(), qName.localName().impl()); |
375 } | 375 } |
376 | 376 |
377 StringImpl* findStringIfStatic(const UChar* characters, unsigned length) | 377 template<typename CharType> |
| 378 inline StringImpl* findStringIfStatic(const CharType* characters, unsigned lengt
h) |
378 { | 379 { |
379 // We don't need to try hashing if we know the string is too long. | 380 // We don't need to try hashing if we know the string is too long. |
380 if (length > StringImpl::highestStaticStringLength()) | 381 if (length > StringImpl::highestStaticStringLength()) |
381 return 0; | 382 return 0; |
382 // computeHashAndMaskTop8Bits is the function StringImpl::hash() uses. | 383 // computeHashAndMaskTop8Bits is the function StringImpl::hash() uses. |
383 unsigned hash = StringHasher::computeHashAndMaskTop8Bits(characters, length)
; | 384 unsigned hash = StringHasher::computeHashAndMaskTop8Bits(characters, length)
; |
384 const WTF::StaticStringsTable& table = StringImpl::allStaticStrings(); | 385 const WTF::StaticStringsTable& table = StringImpl::allStaticStrings(); |
385 ASSERT(!table.isEmpty()); | 386 ASSERT(!table.isEmpty()); |
386 | 387 |
387 WTF::StaticStringsTable::const_iterator it = table.find(hash); | 388 WTF::StaticStringsTable::const_iterator it = table.find(hash); |
388 if (it == table.end()) | 389 if (it == table.end()) |
389 return 0; | 390 return 0; |
390 // It's possible to have hash collisions between arbitrary strings and | 391 // It's possible to have hash collisions between arbitrary strings and |
391 // known identifiers (e.g. "bvvfg" collides with "script"). | 392 // known identifiers (e.g. "bvvfg" collides with "script"). |
392 // However ASSERTs in StringImpl::createStatic guard against there ever bein
g collisions | 393 // However ASSERTs in StringImpl::createStatic guard against there ever bein
g collisions |
393 // between static strings. | 394 // between static strings. |
394 if (!equal(it->value, characters, length)) | 395 if (!equal(it->value, characters, length)) |
395 return 0; | 396 return 0; |
396 return it->value; | 397 return it->value; |
397 } | 398 } |
398 | 399 |
| 400 String attemptStaticStringCreation(const LChar* characters, size_t size) |
| 401 { |
| 402 String string(findStringIfStatic(characters, size)); |
| 403 if (string.impl()) |
| 404 return string; |
| 405 return String(characters, size); |
399 } | 406 } |
| 407 |
| 408 String attemptStaticStringCreation(const UChar* characters, size_t size, Charact
erWidth width) |
| 409 { |
| 410 String string(findStringIfStatic(characters, size)); |
| 411 if (string.impl()) |
| 412 return string; |
| 413 if (width == Likely8Bit) |
| 414 string = StringImpl::create8BitIfPossible(characters, size); |
| 415 else if (width == Force8Bit) |
| 416 string = String::make8BitFrom16BitSource(characters, size); |
| 417 else |
| 418 string = String(characters, size); |
| 419 |
| 420 return string; |
| 421 } |
| 422 |
| 423 } |
OLD | NEW |