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

Unified Diff: Source/core/rendering/FastTextAutosizer.cpp

Issue 186453002: [FastTextAutosizer] Keep m_blocksForFingerprint and m_fingerprints in sync (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Refactr Created 6 years, 10 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
« no previous file with comments | « Source/core/rendering/FastTextAutosizer.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/rendering/FastTextAutosizer.cpp
diff --git a/Source/core/rendering/FastTextAutosizer.cpp b/Source/core/rendering/FastTextAutosizer.cpp
index bd0810acda0e91a23b4cad15404c8a0c8b1f1cbf..b3ea134bb848d728a439af8c5e36eb9c14903908 100644
--- a/Source/core/rendering/FastTextAutosizer.cpp
+++ b/Source/core/rendering/FastTextAutosizer.cpp
@@ -659,9 +659,38 @@ FastTextAutosizer::Cluster* FastTextAutosizer::currentCluster() const
return m_clusterStack.last().get();
}
+#ifndef NDEBUG
+bool FastTextAutosizer::FingerprintMapper::mapsAreConsistent()
+{
+ // For each fingerprint -> block mapping in m_blocksForFingerprint we should have an associated
+ // map from block -> fingerprint in m_fingerprints.
+ ReverseFingerprintMap::iterator end = m_blocksForFingerprint.end();
+ for (ReverseFingerprintMap::iterator fingerprintIt = m_blocksForFingerprint.begin(); fingerprintIt != end; ++fingerprintIt) {
+ Fingerprint fingerprint = fingerprintIt->key;
+ BlockSet* blocks = fingerprintIt->value.get();
+ for (BlockSet::iterator blockIt = blocks->begin(); blockIt != blocks->end(); ++blockIt) {
+ const RenderBlock* block = (*blockIt);
+ ASSERT(m_fingerprints.get(block) == fingerprint);
+ }
+ }
+
+ return true;
skobes 2014/03/05 04:12:22 It's a bit silly to have a return value that is al
pdr. 2014/03/05 04:20:31 Fair point. I was jumping through silly hoops to a
+}
+#endif
+
void FastTextAutosizer::FingerprintMapper::add(const RenderObject* renderer, Fingerprint fingerprint)
{
+ // Make sure to remove any existing fingerprint mapping for this renderer.
+ Fingerprint oldFingerprint = m_fingerprints.get(renderer);
+ if (oldFingerprint && renderer->isRenderBlock()) {
+ ReverseFingerprintMap::iterator blocksIter = m_blocksForFingerprint.find(oldFingerprint);
+ if (blocksIter != m_blocksForFingerprint.end())
+ blocksIter->value->remove(toRenderBlock(renderer));
skobes 2014/03/05 04:12:22 I think I liked it better when this just called Fi
pdr. 2014/03/05 04:20:31 Yeah, I agree. This will have one unnecessary hash
+ }
+
m_fingerprints.set(renderer, fingerprint);
+
+ ASSERT(mapsAreConsistent());
}
void FastTextAutosizer::FingerprintMapper::addTentativeClusterRoot(const RenderBlock* block, Fingerprint fingerprint)
@@ -672,6 +701,7 @@ void FastTextAutosizer::FingerprintMapper::addTentativeClusterRoot(const RenderB
if (addResult.isNewEntry)
addResult.storedValue->value = adoptPtr(new BlockSet);
addResult.storedValue->value->add(block);
+ ASSERT(mapsAreConsistent());
}
void FastTextAutosizer::FingerprintMapper::remove(const RenderObject* renderer)
@@ -688,6 +718,7 @@ void FastTextAutosizer::FingerprintMapper::remove(const RenderObject* renderer)
blocks.remove(toRenderBlock(renderer));
if (blocks.isEmpty())
m_blocksForFingerprint.remove(blocksIter);
+ ASSERT(mapsAreConsistent());
}
FastTextAutosizer::Fingerprint FastTextAutosizer::FingerprintMapper::get(const RenderObject* renderer)
« no previous file with comments | « Source/core/rendering/FastTextAutosizer.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698