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 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
251 | 251 |
252 | 252 |
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 | |
262 BufferOwnership ownership = bufferOwnership(); | |
263 | |
264 if (ownership == BufferInternal) | |
265 return; | |
266 if (ownership == BufferOwned) { | |
267 // We use m_data8, but since it is a union with m_data16 this works eith
er way. | |
268 ASSERT(m_data8); | |
269 fastFree(const_cast<LChar*>(m_data8)); | |
270 return; | |
271 } | |
272 ASSERT_NOT_REACHED(); | |
273 } | 261 } |
274 | 262 |
275 PassRefPtr<StringImpl> StringImpl::createFromLiteral(const char* characters, uns
igned length) | 263 PassRefPtr<StringImpl> StringImpl::createFromLiteral(const char* characters, uns
igned length) |
276 { | 264 { |
277 ASSERT_WITH_MESSAGE(length, "Use StringImpl::empty() to create an empty stri
ng"); | 265 ASSERT_WITH_MESSAGE(length, "Use StringImpl::empty() to create an empty stri
ng"); |
278 ASSERT(charactersAreAllASCII<LChar>(reinterpret_cast<const LChar*>(character
s), length)); | 266 ASSERT(charactersAreAllASCII<LChar>(reinterpret_cast<const LChar*>(character
s), length)); |
279 return adoptRef(new StringImpl(characters, length, ConstructFromLiteral)); | 267 return adoptRef(new StringImpl(characters, length, ConstructFromLiteral)); |
280 } | 268 } |
281 | 269 |
282 PassRefPtr<StringImpl> StringImpl::createFromLiteral(const char* characters) | 270 PassRefPtr<StringImpl> StringImpl::createFromLiteral(const char* characters) |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
319 size_t size = sizeof(StringImpl) + length * sizeof(UChar); | 307 size_t size = sizeof(StringImpl) + length * sizeof(UChar); |
320 StringImpl* string = static_cast<StringImpl*>(fastMalloc(size)); | 308 StringImpl* string = static_cast<StringImpl*>(fastMalloc(size)); |
321 | 309 |
322 data = reinterpret_cast<UChar*>(string + 1); | 310 data = reinterpret_cast<UChar*>(string + 1); |
323 return adoptRef(new (NotNull, string) StringImpl(length)); | 311 return adoptRef(new (NotNull, string) StringImpl(length)); |
324 } | 312 } |
325 | 313 |
326 PassRefPtr<StringImpl> StringImpl::reallocate(PassRefPtr<StringImpl> originalStr
ing, unsigned length, LChar*& data) | 314 PassRefPtr<StringImpl> StringImpl::reallocate(PassRefPtr<StringImpl> originalStr
ing, unsigned length, LChar*& data) |
327 { | 315 { |
328 ASSERT(originalString->is8Bit()); | 316 ASSERT(originalString->is8Bit()); |
| 317 ASSERT(!originalString->isASCIILiteral()); |
329 ASSERT(originalString->hasOneRef()); | 318 ASSERT(originalString->hasOneRef()); |
330 ASSERT(originalString->bufferOwnership() == BufferInternal); | |
331 | 319 |
332 if (!length) { | 320 if (!length) { |
333 data = 0; | 321 data = 0; |
334 return empty(); | 322 return empty(); |
335 } | 323 } |
336 | 324 |
337 // Same as createUninitialized() except here we use fastRealloc. | 325 // Same as createUninitialized() except here we use fastRealloc. |
338 RELEASE_ASSERT(length <= ((std::numeric_limits<unsigned>::max() - sizeof(Str
ingImpl)) / sizeof(LChar))); | 326 RELEASE_ASSERT(length <= ((std::numeric_limits<unsigned>::max() - sizeof(Str
ingImpl)) / sizeof(LChar))); |
339 size_t size = sizeof(StringImpl) + length * sizeof(LChar); | 327 size_t size = sizeof(StringImpl) + length * sizeof(LChar); |
340 originalString->~StringImpl(); | 328 originalString->~StringImpl(); |
341 StringImpl* string = static_cast<StringImpl*>(fastRealloc(originalString.lea
kRef(), size)); | 329 StringImpl* string = static_cast<StringImpl*>(fastRealloc(originalString.lea
kRef(), size)); |
342 | 330 |
343 data = reinterpret_cast<LChar*>(string + 1); | 331 data = reinterpret_cast<LChar*>(string + 1); |
344 return adoptRef(new (NotNull, string) StringImpl(length, Force8BitConstructo
r)); | 332 return adoptRef(new (NotNull, string) StringImpl(length, Force8BitConstructo
r)); |
345 } | 333 } |
346 | 334 |
347 PassRefPtr<StringImpl> StringImpl::reallocate(PassRefPtr<StringImpl> originalStr
ing, unsigned length, UChar*& data) | 335 PassRefPtr<StringImpl> StringImpl::reallocate(PassRefPtr<StringImpl> originalStr
ing, unsigned length, UChar*& data) |
348 { | 336 { |
349 ASSERT(!originalString->is8Bit()); | 337 ASSERT(!originalString->is8Bit()); |
| 338 ASSERT(!originalString->isASCIILiteral()); |
350 ASSERT(originalString->hasOneRef()); | 339 ASSERT(originalString->hasOneRef()); |
351 ASSERT(originalString->bufferOwnership() == BufferInternal); | |
352 | 340 |
353 if (!length) { | 341 if (!length) { |
354 data = 0; | 342 data = 0; |
355 return empty(); | 343 return empty(); |
356 } | 344 } |
357 | 345 |
358 // Same as createUninitialized() except here we use fastRealloc. | 346 // Same as createUninitialized() except here we use fastRealloc. |
359 RELEASE_ASSERT(length <= ((std::numeric_limits<unsigned>::max() - sizeof(Str
ingImpl)) / sizeof(UChar))); | 347 RELEASE_ASSERT(length <= ((std::numeric_limits<unsigned>::max() - sizeof(Str
ingImpl)) / sizeof(UChar))); |
360 size_t size = sizeof(StringImpl) + length * sizeof(UChar); | 348 size_t size = sizeof(StringImpl) + length * sizeof(UChar); |
361 originalString->~StringImpl(); | 349 originalString->~StringImpl(); |
(...skipping 1616 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1978 | 1966 |
1979 size_t StringImpl::sizeInBytes() const | 1967 size_t StringImpl::sizeInBytes() const |
1980 { | 1968 { |
1981 size_t size = length(); | 1969 size_t size = length(); |
1982 if (!is8Bit()) | 1970 if (!is8Bit()) |
1983 size *= 2; | 1971 size *= 2; |
1984 return size + sizeof(*this); | 1972 return size + sizeof(*this); |
1985 } | 1973 } |
1986 | 1974 |
1987 } // namespace WTF | 1975 } // namespace WTF |
OLD | NEW |