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

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

Issue 1405573003: Introduce StringImpl::createPreallocatedStatic (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: +comment. Removed StringImpl::createStatic. Created 5 years, 1 month 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 323 matching lines...) Expand 10 before | Expand all | Expand 10 after
334 334
335 void StringImpl::freezeStaticStrings() 335 void StringImpl::freezeStaticStrings()
336 { 336 {
337 ASSERT(isMainThread()); 337 ASSERT(isMainThread());
338 338
339 #if ENABLE(ASSERT) 339 #if ENABLE(ASSERT)
340 s_allowCreationOfStaticStrings = false; 340 s_allowCreationOfStaticStrings = false;
341 #endif 341 #endif
342 } 342 }
343 343
344
344 unsigned StringImpl::m_highestStaticStringLength = 0; 345 unsigned StringImpl::m_highestStaticStringLength = 0;
345 346
346 StringImpl* StringImpl::createStatic(const char* string, unsigned length, unsign ed hash) 347 StringImpl* StringImpl::createPreallocatedStatic(void* buffer, unsigned length, unsigned hash)
347 { 348 {
348 ASSERT(s_allowCreationOfStaticStrings); 349 ASSERT(s_allowCreationOfStaticStrings);
349 ASSERT(string); 350 ASSERT(buffer);
350 ASSERT(length); 351 ASSERT(length);
351 352
353 StringImpl* impl = static_cast<StringImpl*>(buffer);
354
352 StaticStringsTable::const_iterator it = staticStrings().find(hash); 355 StaticStringsTable::const_iterator it = staticStrings().find(hash);
353 if (it != staticStrings().end()) { 356 if (it != staticStrings().end()) {
354 ASSERT(!memcmp(string, it->value + 1, length * sizeof(LChar))); 357 ASSERT(!memcmp(reinterpret_cast<LChar*>(impl + 1), it->value + 1, length * sizeof(LChar)));
355 return it->value; 358 return it->value;
356 } 359 }
357 360
358 // Allocate a single buffer large enough to contain the StringImpl
359 // struct as well as the data which it contains. This removes one
360 // heap allocation from this call.
361 RELEASE_ASSERT(length <= ((std::numeric_limits<unsigned>::max() - sizeof(Str ingImpl)) / sizeof(LChar)));
362 size_t size = sizeof(StringImpl) + length * sizeof(LChar);
363
364 WTF_ANNOTATE_SCOPED_MEMORY_LEAK;
365 StringImpl* impl = static_cast<StringImpl*>(Partitions::bufferMalloc(size));
366
367 LChar* data = reinterpret_cast<LChar*>(impl + 1);
368 impl = new (impl) StringImpl(length, hash, StaticString); 361 impl = new (impl) StringImpl(length, hash, StaticString);
369 memcpy(data, string, length * sizeof(LChar));
370 #if ENABLE(ASSERT) 362 #if ENABLE(ASSERT)
371 impl->assertHashIsCorrect(); 363 impl->assertHashIsCorrect();
372 #endif 364 #endif
373 365
374 ASSERT(isMainThread()); 366 ASSERT(isMainThread());
375 m_highestStaticStringLength = std::max(m_highestStaticStringLength, length); 367 m_highestStaticStringLength = std::max(m_highestStaticStringLength, length);
376 staticStrings().add(hash, impl); 368 staticStrings().add(hash, impl);
377 WTF_ANNOTATE_BENIGN_RACE(impl, 369 WTF_ANNOTATE_BENIGN_RACE(impl,
378 "Benign race on the reference counter of a static string created by Stri ngImpl::createStatic"); 370 "Benign race on the reference counter of a static string created by Stri ngImpl::createPreallocatedStatic");
379 371
380 return impl; 372 return impl;
381 } 373 }
382 374
383 void StringImpl::reserveStaticStringsCapacityForSize(unsigned size) 375 void StringImpl::reserveStaticStringsCapacityForSize(unsigned size)
384 { 376 {
385 ASSERT(s_allowCreationOfStaticStrings); 377 ASSERT(s_allowCreationOfStaticStrings);
386 staticStrings().reserveCapacityForSize(size); 378 staticStrings().reserveCapacityForSize(size);
387 } 379 }
388 380
(...skipping 1720 matching lines...) Expand 10 before | Expand all | Expand 10 after
2109 } else if (localeIdMatchesLang(localeIdentifier, "lt")) { 2101 } else if (localeIdMatchesLang(localeIdentifier, "lt")) {
2110 // TODO(rob.buis) implement upper-casing rules for lt 2102 // TODO(rob.buis) implement upper-casing rules for lt
2111 // like in StringImpl::upper(locale). 2103 // like in StringImpl::upper(locale).
2112 } 2104 }
2113 } 2105 }
2114 2106
2115 return toUpper(c); 2107 return toUpper(c);
2116 } 2108 }
2117 2109
2118 } // namespace WTF 2110 } // namespace WTF
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/wtf/text/StringImpl.h ('k') | third_party/WebKit/Source/wtf/text/StringStatics.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698