Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2)

Side by Side Diff: Source/wtf/text/StringImpl.cpp

Issue 110843004: Replaced HTMLIdentifier with an atomized string factory function (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Review fixes Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 340 matching lines...) Expand 10 before | Expand all | Expand 10 after
351 // Same as createUninitialized() except here we use realloc. 351 // Same as createUninitialized() except here we use realloc.
352 RELEASE_ASSERT(length <= ((std::numeric_limits<unsigned>::max() - sizeof(Str ingImpl)) / sizeof(UChar))); 352 RELEASE_ASSERT(length <= ((std::numeric_limits<unsigned>::max() - sizeof(Str ingImpl)) / sizeof(UChar)));
353 size_t size = sizeof(StringImpl) + length * sizeof(UChar); 353 size_t size = sizeof(StringImpl) + length * sizeof(UChar);
354 originalString->~StringImpl(); 354 originalString->~StringImpl();
355 StringImpl* string = static_cast<StringImpl*>(partitionReallocGeneric(Partit ions::getBufferPartition(), originalString.leakRef(), size)); 355 StringImpl* string = static_cast<StringImpl*>(partitionReallocGeneric(Partit ions::getBufferPartition(), originalString.leakRef(), size));
356 356
357 data = reinterpret_cast<UChar*>(string + 1); 357 data = reinterpret_cast<UChar*>(string + 1);
358 return adoptRef(new (string) StringImpl(length)); 358 return adoptRef(new (string) StringImpl(length));
359 } 359 }
360 360
361 static Vector<StringImpl*>& staticStrings() 361 static StaticStringsTable& staticStrings()
362 { 362 {
363 DEFINE_STATIC_LOCAL(Vector<StringImpl*>, staticStrings, ()); 363 DEFINE_STATIC_LOCAL(StaticStringsTable, staticStrings, ());
364 return staticStrings; 364 return staticStrings;
365 } 365 }
366 366
367 #ifndef NDEBUG 367 #ifndef NDEBUG
368 static bool s_allowCreationOfStaticStrings = true; 368 static bool s_allowCreationOfStaticStrings = true;
369 #endif 369 #endif
370 370
371 const Vector<StringImpl*>& StringImpl::allStaticStrings() 371 const StaticStringsTable& StringImpl::allStaticStrings()
372 { 372 {
373 return staticStrings(); 373 return staticStrings();
374 } 374 }
375 375
376 void StringImpl::freezeStaticStrings() 376 void StringImpl::freezeStaticStrings()
377 { 377 {
378 ASSERT(isMainThread()); 378 ASSERT(isMainThread());
379 379
380 #ifndef NDEBUG 380 #ifndef NDEBUG
381 s_allowCreationOfStaticStrings = false; 381 s_allowCreationOfStaticStrings = false;
382 #endif 382 #endif
383 }
383 384
384 staticStrings().shrinkToFit(); 385 unsigned StringImpl::m_highestStaticStringLength = 0;
385 }
386 386
387 StringImpl* StringImpl::createStatic(const char* string, unsigned length, unsign ed hash) 387 StringImpl* StringImpl::createStatic(const char* string, unsigned length, unsign ed hash)
388 { 388 {
389 ASSERT(s_allowCreationOfStaticStrings); 389 ASSERT(s_allowCreationOfStaticStrings);
390 ASSERT(string); 390 ASSERT(string);
391 ASSERT(length); 391 ASSERT(length);
392 392
393 // Allocate a single buffer large enough to contain the StringImpl 393 // Allocate a single buffer large enough to contain the StringImpl
394 // struct as well as the data which it contains. This removes one 394 // struct as well as the data which it contains. This removes one
395 // heap allocation from this call. 395 // heap allocation from this call.
396 RELEASE_ASSERT(length <= ((std::numeric_limits<unsigned>::max() - sizeof(Str ingImpl)) / sizeof(LChar))); 396 RELEASE_ASSERT(length <= ((std::numeric_limits<unsigned>::max() - sizeof(Str ingImpl)) / sizeof(LChar)));
397 size_t size = sizeof(StringImpl) + length * sizeof(LChar); 397 size_t size = sizeof(StringImpl) + length * sizeof(LChar);
398 WTF_ANNOTATE_SCOPED_MEMORY_LEAK; 398 WTF_ANNOTATE_SCOPED_MEMORY_LEAK;
399 StringImpl* impl = static_cast<StringImpl*>(partitionAllocGeneric(Partitions ::getBufferPartition(), size)); 399 StringImpl* impl = static_cast<StringImpl*>(partitionAllocGeneric(Partitions ::getBufferPartition(), size));
400 400
401 LChar* data = reinterpret_cast<LChar*>(impl + 1); 401 LChar* data = reinterpret_cast<LChar*>(impl + 1);
402 impl = new (impl) StringImpl(length, hash, StaticString); 402 impl = new (impl) StringImpl(length, hash, StaticString);
403 memcpy(data, string, length * sizeof(LChar)); 403 memcpy(data, string, length * sizeof(LChar));
404 #ifndef NDEBUG 404 #ifndef NDEBUG
405 impl->assertHashIsCorrect(); 405 impl->assertHashIsCorrect();
406 #endif 406 #endif
407 407
408 ASSERT(isMainThread()); 408 ASSERT(isMainThread());
409 staticStrings().append(impl); 409 m_highestStaticStringLength = std::max(m_highestStaticStringLength, length);
410 staticStrings().add(hash, impl);
abarth-chromium 2013/12/10 04:48:23 Can you ASSERT that this hash isn't already in the
oystein (OOO til 10th of July) 2013/12/10 18:42:27 There were actually some duplicates here (SVGNames
410 WTF_ANNOTATE_BENIGN_RACE(impl, 411 WTF_ANNOTATE_BENIGN_RACE(impl,
411 "Benign race on the reference counter of a static string created by Stri ngImpl::createStatic"); 412 "Benign race on the reference counter of a static string created by Stri ngImpl::createStatic");
412 413
413 return impl; 414 return impl;
414 } 415 }
415 416
416 PassRefPtr<StringImpl> StringImpl::create(const UChar* characters, unsigned leng th) 417 PassRefPtr<StringImpl> StringImpl::create(const UChar* characters, unsigned leng th)
417 { 418 {
418 if (!characters || !length) 419 if (!characters || !length)
419 return empty(); 420 return empty();
(...skipping 1663 matching lines...) Expand 10 before | Expand all | Expand 10 after
2083 2084
2084 size_t StringImpl::sizeInBytes() const 2085 size_t StringImpl::sizeInBytes() const
2085 { 2086 {
2086 size_t size = length(); 2087 size_t size = length();
2087 if (!is8Bit()) 2088 if (!is8Bit())
2088 size *= 2; 2089 size *= 2;
2089 return size + sizeof(*this); 2090 return size + sizeof(*this);
2090 } 2091 }
2091 2092
2092 } // namespace WTF 2093 } // namespace WTF
OLDNEW
« Source/core/html/parser/HTMLParserIdioms.cpp ('K') | « Source/wtf/text/StringImpl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698