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 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
253 StringImpl::~StringImpl() | 253 StringImpl::~StringImpl() |
254 { | 254 { |
255 ASSERT(!isStatic()); | 255 ASSERT(!isStatic()); |
256 | 256 |
257 STRING_STATS_REMOVE_STRING(this); | 257 STRING_STATS_REMOVE_STRING(this); |
258 | 258 |
259 if (isAtomic()) | 259 if (isAtomic()) |
260 AtomicString::remove(this); | 260 AtomicString::remove(this); |
261 } | 261 } |
262 | 262 |
263 PassRefPtr<StringImpl> StringImpl::createFromLiteral(const char* characters, uns
igned length) | |
264 { | |
265 ASSERT_WITH_MESSAGE(length, "Use StringImpl::empty() to create an empty stri
ng"); | |
266 ASSERT(charactersAreAllASCII<LChar>(reinterpret_cast<const LChar*>(character
s), length)); | |
267 return adoptRef(new StringImpl(characters, length, ConstructFromLiteral)); | |
268 } | |
269 | |
270 PassRefPtr<StringImpl> StringImpl::createFromLiteral(const char* characters) | |
271 { | |
272 size_t length = strlen(characters); | |
273 ASSERT_WITH_MESSAGE(length, "Use StringImpl::empty() to create an empty stri
ng"); | |
274 ASSERT(charactersAreAllASCII<LChar>(reinterpret_cast<const LChar*>(character
s), length)); | |
275 return adoptRef(new StringImpl(characters, length, ConstructFromLiteral)); | |
276 } | |
277 | |
278 PassRefPtr<StringImpl> StringImpl::createUninitialized(unsigned length, LChar*&
data) | 263 PassRefPtr<StringImpl> StringImpl::createUninitialized(unsigned length, LChar*&
data) |
279 { | 264 { |
280 if (!length) { | 265 if (!length) { |
281 data = 0; | 266 data = 0; |
282 return empty(); | 267 return empty(); |
283 } | 268 } |
284 | 269 |
285 // Allocate a single buffer large enough to contain the StringImpl | 270 // Allocate a single buffer large enough to contain the StringImpl |
286 // struct as well as the data which it contains. This removes one | 271 // struct as well as the data which it contains. This removes one |
287 // heap allocation from this call. | 272 // heap allocation from this call. |
(...skipping 19 matching lines...) Expand all Loading... |
307 size_t size = sizeof(StringImpl) + length * sizeof(UChar); | 292 size_t size = sizeof(StringImpl) + length * sizeof(UChar); |
308 StringImpl* string = static_cast<StringImpl*>(fastMalloc(size)); | 293 StringImpl* string = static_cast<StringImpl*>(fastMalloc(size)); |
309 | 294 |
310 data = reinterpret_cast<UChar*>(string + 1); | 295 data = reinterpret_cast<UChar*>(string + 1); |
311 return adoptRef(new (NotNull, string) StringImpl(length)); | 296 return adoptRef(new (NotNull, string) StringImpl(length)); |
312 } | 297 } |
313 | 298 |
314 PassRefPtr<StringImpl> StringImpl::reallocate(PassRefPtr<StringImpl> originalStr
ing, unsigned length, LChar*& data) | 299 PassRefPtr<StringImpl> StringImpl::reallocate(PassRefPtr<StringImpl> originalStr
ing, unsigned length, LChar*& data) |
315 { | 300 { |
316 ASSERT(originalString->is8Bit()); | 301 ASSERT(originalString->is8Bit()); |
317 ASSERT(!originalString->isASCIILiteral()); | |
318 ASSERT(originalString->hasOneRef()); | 302 ASSERT(originalString->hasOneRef()); |
319 | 303 |
320 if (!length) { | 304 if (!length) { |
321 data = 0; | 305 data = 0; |
322 return empty(); | 306 return empty(); |
323 } | 307 } |
324 | 308 |
325 // Same as createUninitialized() except here we use fastRealloc. | 309 // Same as createUninitialized() except here we use fastRealloc. |
326 RELEASE_ASSERT(length <= ((std::numeric_limits<unsigned>::max() - sizeof(Str
ingImpl)) / sizeof(LChar))); | 310 RELEASE_ASSERT(length <= ((std::numeric_limits<unsigned>::max() - sizeof(Str
ingImpl)) / sizeof(LChar))); |
327 size_t size = sizeof(StringImpl) + length * sizeof(LChar); | 311 size_t size = sizeof(StringImpl) + length * sizeof(LChar); |
328 originalString->~StringImpl(); | 312 originalString->~StringImpl(); |
329 StringImpl* string = static_cast<StringImpl*>(fastRealloc(originalString.lea
kRef(), size)); | 313 StringImpl* string = static_cast<StringImpl*>(fastRealloc(originalString.lea
kRef(), size)); |
330 | 314 |
331 data = reinterpret_cast<LChar*>(string + 1); | 315 data = reinterpret_cast<LChar*>(string + 1); |
332 return adoptRef(new (NotNull, string) StringImpl(length, Force8BitConstructo
r)); | 316 return adoptRef(new (NotNull, string) StringImpl(length, Force8BitConstructo
r)); |
333 } | 317 } |
334 | 318 |
335 PassRefPtr<StringImpl> StringImpl::reallocate(PassRefPtr<StringImpl> originalStr
ing, unsigned length, UChar*& data) | 319 PassRefPtr<StringImpl> StringImpl::reallocate(PassRefPtr<StringImpl> originalStr
ing, unsigned length, UChar*& data) |
336 { | 320 { |
337 ASSERT(!originalString->is8Bit()); | 321 ASSERT(!originalString->is8Bit()); |
338 ASSERT(!originalString->isASCIILiteral()); | |
339 ASSERT(originalString->hasOneRef()); | 322 ASSERT(originalString->hasOneRef()); |
340 | 323 |
341 if (!length) { | 324 if (!length) { |
342 data = 0; | 325 data = 0; |
343 return empty(); | 326 return empty(); |
344 } | 327 } |
345 | 328 |
346 // Same as createUninitialized() except here we use fastRealloc. | 329 // Same as createUninitialized() except here we use fastRealloc. |
347 RELEASE_ASSERT(length <= ((std::numeric_limits<unsigned>::max() - sizeof(Str
ingImpl)) / sizeof(UChar))); | 330 RELEASE_ASSERT(length <= ((std::numeric_limits<unsigned>::max() - sizeof(Str
ingImpl)) / sizeof(UChar))); |
348 size_t size = sizeof(StringImpl) + length * sizeof(UChar); | 331 size_t size = sizeof(StringImpl) + length * sizeof(UChar); |
(...skipping 1617 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1966 | 1949 |
1967 size_t StringImpl::sizeInBytes() const | 1950 size_t StringImpl::sizeInBytes() const |
1968 { | 1951 { |
1969 size_t size = length(); | 1952 size_t size = length(); |
1970 if (!is8Bit()) | 1953 if (!is8Bit()) |
1971 size *= 2; | 1954 size *= 2; |
1972 return size + sizeof(*this); | 1955 return size + sizeof(*this); |
1973 } | 1956 } |
1974 | 1957 |
1975 } // namespace WTF | 1958 } // namespace WTF |
OLD | NEW |