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

Unified Diff: third_party/WebKit/Source/platform/fonts/FontDataCache.cpp

Issue 2031363002: Use a FontPlatformData pointer for FontDataCache's key (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Crashes, lifecycle issues fixed Created 4 years, 6 months 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/platform/fonts/FontDataCache.cpp
diff --git a/third_party/WebKit/Source/platform/fonts/FontDataCache.cpp b/third_party/WebKit/Source/platform/fonts/FontDataCache.cpp
index 4bf5a2c28fc4bb51710f122a8309305dc81fc557..27a18526f0e478cdbdd879ea296dc966a7e2cfec 100644
--- a/third_party/WebKit/Source/platform/fonts/FontDataCache.cpp
+++ b/third_party/WebKit/Source/platform/fonts/FontDataCache.cpp
@@ -57,10 +57,13 @@ PassRefPtr<SimpleFontData> FontDataCache::get(const FontPlatformData* platformDa
return nullptr;
}
- Cache::iterator result = m_cache.find(*platformData);
+ Cache::iterator result = m_cache.find(platformData);
if (result == m_cache.end()) {
std::pair<RefPtr<SimpleFontData>, unsigned> newValue(SimpleFontData::create(*platformData), shouldRetain == Retain ? 1 : 0);
- m_cache.set(*platformData, newValue);
+ // The new SimpleFontData takes a copy of the incoming FontPlatformData object. The incoming key may be
+ // temporary. So, for cache storage, take the address of the newly created FontPlatformData that is copied an
+ // owned by SimpleFontData.
+ m_cache.set(&newValue.first->platformData(), newValue);
if (shouldRetain == DoNotRetain)
m_inactiveFontData.add(newValue.first);
return newValue.first.release();
@@ -84,14 +87,14 @@ PassRefPtr<SimpleFontData> FontDataCache::get(const FontPlatformData* platformDa
bool FontDataCache::contains(const FontPlatformData* fontPlatformData) const
{
- return m_cache.contains(*fontPlatformData);
+ return m_cache.contains(fontPlatformData);
}
void FontDataCache::release(const SimpleFontData* fontData)
{
ASSERT(!fontData->isCustomFont());
- Cache::iterator it = m_cache.find(fontData->platformData());
+ Cache::iterator it = m_cache.find(&(fontData->platformData()));
ASSERT(it != m_cache.end());
if (it == m_cache.end())
return;
@@ -135,7 +138,7 @@ bool FontDataCache::purgeLeastRecentlyUsed(int count)
ListHashSet<RefPtr<SimpleFontData>>::iterator it = m_inactiveFontData.begin();
for (int i = 0; i < count && it != end; ++it, ++i) {
RefPtr<SimpleFontData>& fontData = *it.get();
- m_cache.remove(fontData->platformData());
+ m_cache.remove(&(fontData->platformData()));
// We should not delete SimpleFontData here because deletion can modify m_inactiveFontData. See http://trac.webkit.org/changeset/44011
fontDataToDelete.append(fontData);
}

Powered by Google App Engine
This is Rietveld 408576698