OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) | 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) |
3 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2013 Apple Inc. All rights | 3 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2013 Apple Inc. All rights |
4 * reserved. | 4 * reserved. |
5 * Copyright (C) 2009 Google Inc. All rights reserved. | 5 * Copyright (C) 2009 Google Inc. All rights reserved. |
6 * | 6 * |
7 * This library is free software; you can redistribute it and/or | 7 * This library is free software; you can redistribute it and/or |
8 * modify it under the terms of the GNU Library General Public | 8 * modify it under the terms of the GNU Library General Public |
9 * License as published by the Free Software Foundation; either | 9 * License as published by the Free Software Foundation; either |
10 * version 2 of the License, or (at your option) any later version. | 10 * version 2 of the License, or (at your option) any later version. |
(...skipping 17 matching lines...) Expand all Loading... |
28 #include "wtf/Forward.h" | 28 #include "wtf/Forward.h" |
29 #include "wtf/HashMap.h" | 29 #include "wtf/HashMap.h" |
30 #include "wtf/StringHasher.h" | 30 #include "wtf/StringHasher.h" |
31 #include "wtf/Vector.h" | 31 #include "wtf/Vector.h" |
32 #include "wtf/WTFExport.h" | 32 #include "wtf/WTFExport.h" |
33 #include "wtf/text/ASCIIFastPath.h" | 33 #include "wtf/text/ASCIIFastPath.h" |
34 #include "wtf/text/Unicode.h" | 34 #include "wtf/text/Unicode.h" |
35 #include <limits.h> | 35 #include <limits.h> |
36 #include <string.h> | 36 #include <string.h> |
37 | 37 |
| 38 #if DCHECK_IS_ON() |
| 39 #include "wtf/ThreadRestrictionVerifier.h" |
| 40 #endif |
| 41 |
38 #if OS(MACOSX) | 42 #if OS(MACOSX) |
39 typedef const struct __CFString* CFStringRef; | 43 typedef const struct __CFString* CFStringRef; |
40 #endif | 44 #endif |
41 | 45 |
42 #ifdef __OBJC__ | 46 #ifdef __OBJC__ |
43 @class NSString; | 47 @class NSString; |
44 #endif | 48 #endif |
45 | 49 |
46 namespace WTF { | 50 namespace WTF { |
47 | 51 |
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
290 DCHECK(hasHash()); | 294 DCHECK(hasHash()); |
291 return m_hash; | 295 return m_hash; |
292 } | 296 } |
293 | 297 |
294 unsigned hash() const { | 298 unsigned hash() const { |
295 if (hasHash()) | 299 if (hasHash()) |
296 return existingHash(); | 300 return existingHash(); |
297 return hashSlowCase(); | 301 return hashSlowCase(); |
298 } | 302 } |
299 | 303 |
300 ALWAYS_INLINE bool hasOneRef() const { return m_refCount == 1; } | 304 ALWAYS_INLINE bool hasOneRef() const { |
| 305 #if DCHECK_IS_ON() |
| 306 DCHECK(isStatic() || m_verifier.isSafeToUse()) << asciiForDebugging(); |
| 307 #endif |
| 308 return m_refCount == 1; |
| 309 } |
301 | 310 |
302 ALWAYS_INLINE void ref() { ++m_refCount; } | 311 ALWAYS_INLINE void ref() const { |
| 312 #if DCHECK_IS_ON() |
| 313 DCHECK(isStatic() || m_verifier.onRef(m_refCount)) << asciiForDebugging(); |
| 314 #endif |
| 315 ++m_refCount; |
| 316 } |
303 | 317 |
304 ALWAYS_INLINE void deref() { | 318 ALWAYS_INLINE void deref() const { |
| 319 #if DCHECK_IS_ON() |
| 320 DCHECK(isStatic() || m_verifier.onDeref(m_refCount)) |
| 321 << asciiForDebugging() << " " << currentThread(); |
| 322 #endif |
305 if (!--m_refCount) | 323 if (!--m_refCount) |
306 destroyIfNotStatic(); | 324 destroyIfNotStatic(); |
307 } | 325 } |
308 | 326 |
309 static StringImpl* empty(); | 327 static StringImpl* empty(); |
310 static StringImpl* empty16Bit(); | 328 static StringImpl* empty16Bit(); |
311 | 329 |
312 // FIXME: Does this really belong in StringImpl? | 330 // FIXME: Does this really belong in StringImpl? |
313 template <typename T> | 331 template <typename T> |
314 static void copyChars(T* destination, | 332 static void copyChars(T* destination, |
315 const T* source, | 333 const T* source, |
316 unsigned numCharacters) { | 334 unsigned numCharacters) { |
317 memcpy(destination, source, numCharacters * sizeof(T)); | 335 memcpy(destination, source, numCharacters * sizeof(T)); |
318 } | 336 } |
319 | 337 |
320 ALWAYS_INLINE static void copyChars(UChar* destination, | 338 ALWAYS_INLINE static void copyChars(UChar* destination, |
321 const LChar* source, | 339 const LChar* source, |
322 unsigned numCharacters) { | 340 unsigned numCharacters) { |
323 for (unsigned i = 0; i < numCharacters; ++i) | 341 for (unsigned i = 0; i < numCharacters; ++i) |
324 destination[i] = source[i]; | 342 destination[i] = source[i]; |
325 } | 343 } |
326 | 344 |
327 // Some string features, like refcounting and the atomicity flag, are not | 345 // Some string features, like refcounting and the atomicity flag, are not |
328 // thread-safe. We achieve thread safety by isolation, giving each thread | 346 // thread-safe. We achieve thread safety by isolation, giving each thread |
329 // its own copy of the string. | 347 // its own copy of the string. |
330 PassRefPtr<StringImpl> isolatedCopy() const; | 348 PassRefPtr<StringImpl> isolatedCopy() const; |
331 | 349 |
332 PassRefPtr<StringImpl> substring(unsigned pos, unsigned len = UINT_MAX); | 350 PassRefPtr<StringImpl> substring(unsigned pos, unsigned len = UINT_MAX) const; |
333 | 351 |
334 UChar operator[](unsigned i) const { | 352 UChar operator[](unsigned i) const { |
335 SECURITY_DCHECK(i < m_length); | 353 SECURITY_DCHECK(i < m_length); |
336 if (is8Bit()) | 354 if (is8Bit()) |
337 return characters8()[i]; | 355 return characters8()[i]; |
338 return characters16()[i]; | 356 return characters16()[i]; |
339 } | 357 } |
340 UChar32 characterStartingAt(unsigned); | 358 UChar32 characterStartingAt(unsigned); |
341 | 359 |
342 bool containsOnlyWhitespace(); | 360 bool containsOnlyWhitespace(); |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
480 const UChar* replacement, | 498 const UChar* replacement, |
481 unsigned replacementLength); | 499 unsigned replacementLength); |
482 | 500 |
483 template <class UCharPredicate> | 501 template <class UCharPredicate> |
484 PassRefPtr<StringImpl> stripMatchedCharacters(UCharPredicate); | 502 PassRefPtr<StringImpl> stripMatchedCharacters(UCharPredicate); |
485 template <typename CharType, class UCharPredicate> | 503 template <typename CharType, class UCharPredicate> |
486 PassRefPtr<StringImpl> simplifyMatchedCharactersToSpace(UCharPredicate, | 504 PassRefPtr<StringImpl> simplifyMatchedCharactersToSpace(UCharPredicate, |
487 StripBehavior); | 505 StripBehavior); |
488 NEVER_INLINE unsigned hashSlowCase() const; | 506 NEVER_INLINE unsigned hashSlowCase() const; |
489 | 507 |
490 void destroyIfNotStatic(); | 508 void destroyIfNotStatic() const; |
491 void updateContainsOnlyASCII() const; | 509 void updateContainsOnlyASCII() const; |
492 | 510 |
| 511 #if DCHECK_IS_ON() |
| 512 std::string asciiForDebugging() const; |
| 513 #endif |
| 514 |
493 #ifdef STRING_STATS | 515 #ifdef STRING_STATS |
494 static StringStats m_stringStats; | 516 static StringStats m_stringStats; |
495 #endif | 517 #endif |
496 | 518 |
497 static unsigned m_highestStaticStringLength; | 519 static unsigned m_highestStaticStringLength; |
498 | 520 |
499 #if DCHECK_IS_ON() | 521 #if DCHECK_IS_ON() |
500 void assertHashIsCorrect() { | 522 void assertHashIsCorrect() { |
501 DCHECK(hasHash()); | 523 DCHECK(hasHash()); |
502 DCHECK_EQ(existingHash(), StringHasher::computeHashAndMaskTop8Bits( | 524 DCHECK_EQ(existingHash(), StringHasher::computeHashAndMaskTop8Bits( |
503 characters8(), length())); | 525 characters8(), length())); |
504 } | 526 } |
505 #endif | 527 #endif |
506 | 528 |
507 private: | 529 private: |
508 unsigned m_refCount; | 530 mutable unsigned m_refCount; |
509 const unsigned m_length; | 531 const unsigned m_length; |
510 mutable unsigned m_hash : 24; | 532 mutable unsigned m_hash : 24; |
511 mutable unsigned m_containsOnlyASCII : 1; | 533 mutable unsigned m_containsOnlyASCII : 1; |
512 mutable unsigned m_needsASCIICheck : 1; | 534 mutable unsigned m_needsASCIICheck : 1; |
513 unsigned m_isAtomic : 1; | 535 unsigned m_isAtomic : 1; |
514 const unsigned m_is8Bit : 1; | 536 const unsigned m_is8Bit : 1; |
515 const unsigned m_isStatic : 1; | 537 const unsigned m_isStatic : 1; |
| 538 |
| 539 #if DCHECK_IS_ON() |
| 540 mutable ThreadRestrictionVerifier m_verifier; |
| 541 #endif |
516 }; | 542 }; |
517 | 543 |
518 template <> | 544 template <> |
519 ALWAYS_INLINE const LChar* StringImpl::getCharacters<LChar>() const { | 545 ALWAYS_INLINE const LChar* StringImpl::getCharacters<LChar>() const { |
520 return characters8(); | 546 return characters8(); |
521 } | 547 } |
522 | 548 |
523 template <> | 549 template <> |
524 ALWAYS_INLINE const UChar* StringImpl::getCharacters<UChar>() const { | 550 ALWAYS_INLINE const UChar* StringImpl::getCharacters<UChar>() const { |
525 return characters16(); | 551 return characters16(); |
(...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
860 using WTF::TextCaseASCIIInsensitive; | 886 using WTF::TextCaseASCIIInsensitive; |
861 using WTF::TextCaseUnicodeInsensitive; | 887 using WTF::TextCaseUnicodeInsensitive; |
862 using WTF::TextCaseSensitive; | 888 using WTF::TextCaseSensitive; |
863 using WTF::TextCaseSensitivity; | 889 using WTF::TextCaseSensitivity; |
864 using WTF::equal; | 890 using WTF::equal; |
865 using WTF::equalNonNull; | 891 using WTF::equalNonNull; |
866 using WTF::lengthOfNullTerminatedString; | 892 using WTF::lengthOfNullTerminatedString; |
867 using WTF::reverseFind; | 893 using WTF::reverseFind; |
868 | 894 |
869 #endif | 895 #endif |
OLD | NEW |