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 r
ights reserved. | 5 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2013 Apple Inc. All r
ights reserved. |
6 * Copyright (C) 2006 Andrew Wellington (proton@wiretapped.net) | 6 * Copyright (C) 2006 Andrew Wellington (proton@wiretapped.net) |
7 * | 7 * |
8 * This library is free software; you can redistribute it and/or | 8 * This library is free software; you can redistribute it and/or |
9 * modify it under the terms of the GNU Library General Public | 9 * modify it under the terms of the GNU Library General Public |
10 * License as published by the Free Software Foundation; either | 10 * License as published by the Free Software Foundation; either |
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
334 return adoptRef(new (string) StringImpl(length, Force8BitConstructor)); | 334 return adoptRef(new (string) StringImpl(length, Force8BitConstructor)); |
335 return adoptRef(new (string) StringImpl(length)); | 335 return adoptRef(new (string) StringImpl(length)); |
336 } | 336 } |
337 | 337 |
338 static StaticStringsTable& staticStrings() | 338 static StaticStringsTable& staticStrings() |
339 { | 339 { |
340 DEFINE_STATIC_LOCAL(StaticStringsTable, staticStrings, ()); | 340 DEFINE_STATIC_LOCAL(StaticStringsTable, staticStrings, ()); |
341 return staticStrings; | 341 return staticStrings; |
342 } | 342 } |
343 | 343 |
344 #ifndef NDEBUG | 344 #if ENABLE(ASSERT) |
345 static bool s_allowCreationOfStaticStrings = true; | 345 static bool s_allowCreationOfStaticStrings = true; |
346 #endif | 346 #endif |
347 | 347 |
348 const StaticStringsTable& StringImpl::allStaticStrings() | 348 const StaticStringsTable& StringImpl::allStaticStrings() |
349 { | 349 { |
350 return staticStrings(); | 350 return staticStrings(); |
351 } | 351 } |
352 | 352 |
353 void StringImpl::freezeStaticStrings() | 353 void StringImpl::freezeStaticStrings() |
354 { | 354 { |
355 ASSERT(isMainThread()); | 355 ASSERT(isMainThread()); |
356 | 356 |
357 #ifndef NDEBUG | 357 #if ENABLE(ASSERT) |
358 s_allowCreationOfStaticStrings = false; | 358 s_allowCreationOfStaticStrings = false; |
359 #endif | 359 #endif |
360 } | 360 } |
361 | 361 |
362 unsigned StringImpl::m_highestStaticStringLength = 0; | 362 unsigned StringImpl::m_highestStaticStringLength = 0; |
363 | 363 |
364 StringImpl* StringImpl::createStatic(const char* string, unsigned length, unsign
ed hash) | 364 StringImpl* StringImpl::createStatic(const char* string, unsigned length, unsign
ed hash) |
365 { | 365 { |
366 ASSERT(s_allowCreationOfStaticStrings); | 366 ASSERT(s_allowCreationOfStaticStrings); |
367 ASSERT(string); | 367 ASSERT(string); |
(...skipping 10 matching lines...) Expand all Loading... |
378 // heap allocation from this call. | 378 // heap allocation from this call. |
379 RELEASE_ASSERT(length <= ((std::numeric_limits<unsigned>::max() - sizeof(Str
ingImpl)) / sizeof(LChar))); | 379 RELEASE_ASSERT(length <= ((std::numeric_limits<unsigned>::max() - sizeof(Str
ingImpl)) / sizeof(LChar))); |
380 size_t size = sizeof(StringImpl) + length * sizeof(LChar); | 380 size_t size = sizeof(StringImpl) + length * sizeof(LChar); |
381 | 381 |
382 WTF_ANNOTATE_SCOPED_MEMORY_LEAK; | 382 WTF_ANNOTATE_SCOPED_MEMORY_LEAK; |
383 StringImpl* impl = static_cast<StringImpl*>(partitionAllocGeneric(Partitions
::getBufferPartition(), size)); | 383 StringImpl* impl = static_cast<StringImpl*>(partitionAllocGeneric(Partitions
::getBufferPartition(), size)); |
384 | 384 |
385 LChar* data = reinterpret_cast<LChar*>(impl + 1); | 385 LChar* data = reinterpret_cast<LChar*>(impl + 1); |
386 impl = new (impl) StringImpl(length, hash, StaticString); | 386 impl = new (impl) StringImpl(length, hash, StaticString); |
387 memcpy(data, string, length * sizeof(LChar)); | 387 memcpy(data, string, length * sizeof(LChar)); |
388 #ifndef NDEBUG | 388 #if ENABLE(ASSERT) |
389 impl->assertHashIsCorrect(); | 389 impl->assertHashIsCorrect(); |
390 #endif | 390 #endif |
391 | 391 |
392 ASSERT(isMainThread()); | 392 ASSERT(isMainThread()); |
393 m_highestStaticStringLength = std::max(m_highestStaticStringLength, length); | 393 m_highestStaticStringLength = std::max(m_highestStaticStringLength, length); |
394 staticStrings().add(hash, impl); | 394 staticStrings().add(hash, impl); |
395 WTF_ANNOTATE_BENIGN_RACE(impl, | 395 WTF_ANNOTATE_BENIGN_RACE(impl, |
396 "Benign race on the reference counter of a static string created by Stri
ngImpl::createStatic"); | 396 "Benign race on the reference counter of a static string created by Stri
ngImpl::createStatic"); |
397 | 397 |
398 return impl; | 398 return impl; |
(...skipping 1700 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2099 | 2099 |
2100 size_t StringImpl::sizeInBytes() const | 2100 size_t StringImpl::sizeInBytes() const |
2101 { | 2101 { |
2102 size_t size = length(); | 2102 size_t size = length(); |
2103 if (!is8Bit()) | 2103 if (!is8Bit()) |
2104 size *= 2; | 2104 size *= 2; |
2105 return size + sizeof(*this); | 2105 return size + sizeof(*this); |
2106 } | 2106 } |
2107 | 2107 |
2108 } // namespace WTF | 2108 } // namespace WTF |
OLD | NEW |