OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) | 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) |
3 * (C) 1999 Antti Koivisto (koivisto@kde.org) | 3 * (C) 1999 Antti Koivisto (koivisto@kde.org) |
4 * (C) 2001 Dirk Mueller ( mueller@kde.org ) | 4 * (C) 2001 Dirk Mueller ( mueller@kde.org ) |
5 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2013 Apple Inc. All | 5 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2013 Apple Inc. All |
6 * rights reserved. | 6 * rights reserved. |
7 * Copyright (C) 2006 Andrew Wellington (proton@wiretapped.net) | 7 * Copyright (C) 2006 Andrew Wellington (proton@wiretapped.net) |
8 * | 8 * |
9 * This library is free software; you can redistribute it and/or | 9 * This library is free software; you can redistribute it and/or |
10 * modify it under the terms of the GNU Library General Public | 10 * modify it under the terms of the GNU Library General Public |
(...skipping 14 matching lines...) Expand all Loading... | |
25 | 25 |
26 #include "wtf/text/StringImpl.h" | 26 #include "wtf/text/StringImpl.h" |
27 | 27 |
28 #include "wtf/DynamicAnnotations.h" | 28 #include "wtf/DynamicAnnotations.h" |
29 #include "wtf/LeakAnnotations.h" | 29 #include "wtf/LeakAnnotations.h" |
30 #include "wtf/PtrUtil.h" | 30 #include "wtf/PtrUtil.h" |
31 #include "wtf/StdLibExtras.h" | 31 #include "wtf/StdLibExtras.h" |
32 #include "wtf/allocator/Partitions.h" | 32 #include "wtf/allocator/Partitions.h" |
33 #include "wtf/text/AtomicString.h" | 33 #include "wtf/text/AtomicString.h" |
34 #include "wtf/text/AtomicStringTable.h" | 34 #include "wtf/text/AtomicStringTable.h" |
35 #include "wtf/text/CString.h" | |
35 #include "wtf/text/CharacterNames.h" | 36 #include "wtf/text/CharacterNames.h" |
36 #include "wtf/text/StringBuffer.h" | 37 #include "wtf/text/StringBuffer.h" |
37 #include "wtf/text/StringHash.h" | 38 #include "wtf/text/StringHash.h" |
38 #include "wtf/text/StringToNumber.h" | 39 #include "wtf/text/StringToNumber.h" |
39 #include <algorithm> | 40 #include <algorithm> |
40 #include <memory> | 41 #include <memory> |
41 | 42 |
42 #ifdef STRING_STATS | 43 #ifdef STRING_STATS |
43 #include "wtf/DataLog.h" | 44 #include "wtf/DataLog.h" |
44 #include "wtf/HashMap.h" | 45 #include "wtf/HashMap.h" |
45 #include "wtf/HashSet.h" | 46 #include "wtf/HashSet.h" |
46 #include "wtf/RefCounted.h" | 47 #include "wtf/RefCounted.h" |
47 #include "wtf/ThreadingPrimitives.h" | 48 #include "wtf/ThreadingPrimitives.h" |
48 #include <unistd.h> | 49 #include <unistd.h> |
49 #endif | 50 #endif |
50 | 51 |
51 using namespace std; | 52 using namespace std; |
52 | 53 |
53 namespace WTF { | 54 namespace WTF { |
54 | 55 |
55 using namespace Unicode; | 56 using namespace Unicode; |
56 | 57 |
58 #if !DCHECK_IS_ON() | |
esprehn
2017/01/13 22:35:29
I'd prefer we changed this to have a side for DCHE
| |
57 static_assert(sizeof(StringImpl) == 3 * sizeof(int), | 59 static_assert(sizeof(StringImpl) == 3 * sizeof(int), |
58 "StringImpl should stay small"); | 60 "StringImpl should stay small"); |
61 #endif | |
59 | 62 |
60 #ifdef STRING_STATS | 63 #ifdef STRING_STATS |
61 | 64 |
62 static Mutex& statsMutex() { | 65 static Mutex& statsMutex() { |
63 DEFINE_STATIC_LOCAL(Mutex, mutex, ()); | 66 DEFINE_STATIC_LOCAL(Mutex, mutex, ()); |
64 return mutex; | 67 return mutex; |
65 } | 68 } |
66 | 69 |
67 static HashSet<void*>& liveStrings() { | 70 static HashSet<void*>& liveStrings() { |
68 // Notice that we can't use HashSet<StringImpl*> because then HashSet would | 71 // Notice that we can't use HashSet<StringImpl*> because then HashSet would |
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
293 | 296 |
294 inline StringImpl::~StringImpl() { | 297 inline StringImpl::~StringImpl() { |
295 DCHECK(!isStatic()); | 298 DCHECK(!isStatic()); |
296 | 299 |
297 STRING_STATS_REMOVE_STRING(this); | 300 STRING_STATS_REMOVE_STRING(this); |
298 | 301 |
299 if (isAtomic()) | 302 if (isAtomic()) |
300 AtomicStringTable::instance().remove(this); | 303 AtomicStringTable::instance().remove(this); |
301 } | 304 } |
302 | 305 |
303 void StringImpl::destroyIfNotStatic() { | 306 void StringImpl::destroyIfNotStatic() const { |
304 if (!isStatic()) | 307 if (!isStatic()) |
305 delete this; | 308 delete this; |
306 } | 309 } |
307 | 310 |
308 void StringImpl::updateContainsOnlyASCII() const { | 311 void StringImpl::updateContainsOnlyASCII() const { |
309 m_containsOnlyASCII = is8Bit() | 312 m_containsOnlyASCII = is8Bit() |
310 ? charactersAreAllASCII(characters8(), length()) | 313 ? charactersAreAllASCII(characters8(), length()) |
311 : charactersAreAllASCII(characters16(), length()); | 314 : charactersAreAllASCII(characters16(), length()); |
312 m_needsASCIICheck = false; | 315 m_needsASCIICheck = false; |
313 } | 316 } |
314 | 317 |
315 bool StringImpl::isSafeToSendToAnotherThread() const { | 318 bool StringImpl::isSafeToSendToAnotherThread() const { |
316 if (isStatic()) | 319 if (isStatic()) |
317 return true; | 320 return true; |
318 // AtomicStrings are not safe to send between threads as ~StringImpl() | 321 // AtomicStrings are not safe to send between threads as ~StringImpl() |
319 // will try to remove them from the wrong AtomicStringTable. | 322 // will try to remove them from the wrong AtomicStringTable. |
320 if (isAtomic()) | 323 if (isAtomic()) |
321 return false; | 324 return false; |
322 if (hasOneRef()) | 325 if (hasOneRef()) |
323 return true; | 326 return true; |
324 return false; | 327 return false; |
325 } | 328 } |
326 | 329 |
330 #if DCHECK_IS_ON() | |
331 std::string StringImpl::asciiForDebugging() const { | |
332 CString ascii = String(substring(0, 128)).ascii(); | |
333 return std::string(ascii.data(), ascii.length()); | |
334 } | |
335 #endif | |
336 | |
327 PassRefPtr<StringImpl> StringImpl::createUninitialized(unsigned length, | 337 PassRefPtr<StringImpl> StringImpl::createUninitialized(unsigned length, |
328 LChar*& data) { | 338 LChar*& data) { |
329 if (!length) { | 339 if (!length) { |
330 data = 0; | 340 data = 0; |
331 return empty(); | 341 return empty(); |
332 } | 342 } |
333 | 343 |
334 // Allocate a single buffer large enough to contain the StringImpl | 344 // Allocate a single buffer large enough to contain the StringImpl |
335 // struct as well as the data which it contains. This removes one | 345 // struct as well as the data which it contains. This removes one |
336 // heap allocation from this call. | 346 // heap allocation from this call. |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
494 } | 504 } |
495 | 505 |
496 for (unsigned i = 0; i < m_length; ++i) { | 506 for (unsigned i = 0; i < m_length; ++i) { |
497 UChar c = characters16()[i]; | 507 UChar c = characters16()[i]; |
498 if (!isASCIISpace(c)) | 508 if (!isASCIISpace(c)) |
499 return false; | 509 return false; |
500 } | 510 } |
501 return true; | 511 return true; |
502 } | 512 } |
503 | 513 |
504 PassRefPtr<StringImpl> StringImpl::substring(unsigned start, unsigned length) { | 514 PassRefPtr<StringImpl> StringImpl::substring(unsigned start, |
515 unsigned length) const { | |
505 if (start >= m_length) | 516 if (start >= m_length) |
506 return empty(); | 517 return empty(); |
507 unsigned maxLength = m_length - start; | 518 unsigned maxLength = m_length - start; |
508 if (length >= maxLength) { | 519 if (length >= maxLength) { |
520 // PassRefPtr has trouble dealing with const arguments. It should be updated | |
521 // so this const_cast is not necessary. | |
509 if (!start) | 522 if (!start) |
510 return this; | 523 return const_cast<StringImpl*>(this); |
511 length = maxLength; | 524 length = maxLength; |
512 } | 525 } |
513 if (is8Bit()) | 526 if (is8Bit()) |
514 return create(characters8() + start, length); | 527 return create(characters8() + start, length); |
515 | 528 |
516 return create(characters16() + start, length); | 529 return create(characters16() + start, length); |
517 } | 530 } |
518 | 531 |
519 UChar32 StringImpl::characterStartingAt(unsigned i) { | 532 UChar32 StringImpl::characterStartingAt(unsigned i) { |
520 if (is8Bit()) | 533 if (is8Bit()) |
(...skipping 1656 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2177 } else if (localeIdMatchesLang(localeIdentifier, "lt")) { | 2190 } else if (localeIdMatchesLang(localeIdentifier, "lt")) { |
2178 // TODO(rob.buis) implement upper-casing rules for lt | 2191 // TODO(rob.buis) implement upper-casing rules for lt |
2179 // like in StringImpl::upper(locale). | 2192 // like in StringImpl::upper(locale). |
2180 } | 2193 } |
2181 } | 2194 } |
2182 | 2195 |
2183 return toUpper(c); | 2196 return toUpper(c); |
2184 } | 2197 } |
2185 | 2198 |
2186 } // namespace WTF | 2199 } // namespace WTF |
OLD | NEW |