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 |
11 * version 2 of the License, or (at your option) any later version. | 11 * version 2 of the License, or (at your option) any later version. |
12 * | 12 * |
13 * This library is distributed in the hope that it will be useful, | 13 * This library is distributed in the hope that it will be useful, |
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
16 * Library General Public License for more details. | 16 * Library General Public License for more details. |
17 * | 17 * |
18 * You should have received a copy of the GNU Library General Public License | 18 * You should have received a copy of the GNU Library General Public License |
19 * along with this library; see the file COPYING.LIB. If not, write to | 19 * along with this library; see the file COPYING.LIB. If not, write to |
20 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 20 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
21 * Boston, MA 02110-1301, USA. | 21 * Boston, MA 02110-1301, USA. |
22 * | 22 * |
23 */ | 23 */ |
24 | 24 |
25 #include "config.h" | 25 #include "config.h" |
26 #include "wtf/text/StringImpl.h" | 26 #include "wtf/text/StringImpl.h" |
27 | 27 |
| 28 #include "wtf/LeakAnnotations.h" |
28 #include "wtf/StdLibExtras.h" | 29 #include "wtf/StdLibExtras.h" |
29 #include "wtf/text/AtomicString.h" | 30 #include "wtf/text/AtomicString.h" |
30 #include "wtf/text/StringBuffer.h" | 31 #include "wtf/text/StringBuffer.h" |
31 #include "wtf/text/StringHash.h" | 32 #include "wtf/text/StringHash.h" |
32 #include "wtf/unicode/CharacterNames.h" | 33 #include "wtf/unicode/CharacterNames.h" |
33 | 34 |
34 #ifdef STRING_STATS | 35 #ifdef STRING_STATS |
35 #include "wtf/DataLog.h" | 36 #include "wtf/DataLog.h" |
36 #include "wtf/MainThread.h" | 37 #include "wtf/MainThread.h" |
37 #include "wtf/ProcessID.h" | 38 #include "wtf/ProcessID.h" |
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
338 StringImpl* StringImpl::createStatic(const char* string, unsigned length, unsign
ed hash) | 339 StringImpl* StringImpl::createStatic(const char* string, unsigned length, unsign
ed hash) |
339 { | 340 { |
340 ASSERT(string); | 341 ASSERT(string); |
341 ASSERT(length); | 342 ASSERT(length); |
342 | 343 |
343 // Allocate a single buffer large enough to contain the StringImpl | 344 // Allocate a single buffer large enough to contain the StringImpl |
344 // 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 |
345 // heap allocation from this call. | 346 // heap allocation from this call. |
346 RELEASE_ASSERT(length <= ((std::numeric_limits<unsigned>::max() - sizeof(Str
ingImpl)) / sizeof(LChar))); | 347 RELEASE_ASSERT(length <= ((std::numeric_limits<unsigned>::max() - sizeof(Str
ingImpl)) / sizeof(LChar))); |
347 size_t size = sizeof(StringImpl) + length * sizeof(LChar); | 348 size_t size = sizeof(StringImpl) + length * sizeof(LChar); |
| 349 WTF_ANNOTATE_SCOPED_MEMORY_LEAK; |
348 StringImpl* impl = static_cast<StringImpl*>(fastMalloc(size)); | 350 StringImpl* impl = static_cast<StringImpl*>(fastMalloc(size)); |
349 | 351 |
350 LChar* data = reinterpret_cast<LChar*>(impl + 1); | 352 LChar* data = reinterpret_cast<LChar*>(impl + 1); |
351 impl = new (NotNull, impl) StringImpl(length, hash, StaticString); | 353 impl = new (NotNull, impl) StringImpl(length, hash, StaticString); |
352 memcpy(data, string, length * sizeof(LChar)); | 354 memcpy(data, string, length * sizeof(LChar)); |
353 #ifndef NDEBUG | 355 #ifndef NDEBUG |
354 impl->assertHashIsCorrect(); | 356 impl->assertHashIsCorrect(); |
355 #endif | 357 #endif |
356 return impl; | 358 return impl; |
357 } | 359 } |
(...skipping 1611 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1969 | 1971 |
1970 size_t StringImpl::sizeInBytes() const | 1972 size_t StringImpl::sizeInBytes() const |
1971 { | 1973 { |
1972 size_t size = length(); | 1974 size_t size = length(); |
1973 if (!is8Bit()) | 1975 if (!is8Bit()) |
1974 size *= 2; | 1976 size *= 2; |
1975 return size + sizeof(*this); | 1977 return size + sizeof(*this); |
1976 } | 1978 } |
1977 | 1979 |
1978 } // namespace WTF | 1980 } // namespace WTF |
OLD | NEW |