Commit 90795d5e authored by pdr@chromium.org's avatar pdr@chromium.org

[FastTextAutosizer] Keep m_blocksForFingerprint and m_fingerprints in sync

This patch keeps m_blocksForFingerprint in sync with m_fingerprints when
adding a new entry to m_fingerprints. Here's a quick summary about
these maps:
m_blocksForFingerprint maps Fingerprint -> list of RenderBlocks
m_fingerprints maps RenderObject -> Fingerprint

Previously, when adding a block to m_fingerprints we could neglect to
update m_blocksForFingerprint. By removing entries from
m_blocksForFingerprint before registering a new block fingerprint, we
prevent a crash on [1].

[1] http://www.chicagotribune.com/news/sns-wp-blm-news-bc-inventor01-20140301,0,255272.story

TEST=Added an assert that crashes all over our layouttests without this fix. Manually verified [1] no longer crashes.
BUG=348463
NOTRY=true

Review URL: https://codereview.chromium.org/186453002

git-svn-id: svn://svn.chromium.org/blink/trunk@168533 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 1826dde8
...@@ -659,9 +659,31 @@ FastTextAutosizer::Cluster* FastTextAutosizer::currentCluster() const ...@@ -659,9 +659,31 @@ FastTextAutosizer::Cluster* FastTextAutosizer::currentCluster() const
return m_clusterStack.last().get(); return m_clusterStack.last().get();
} }
#ifndef NDEBUG
void FastTextAutosizer::FingerprintMapper::assertMapsAreConsistent()
{
// 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);
}
}
}
#endif
void FastTextAutosizer::FingerprintMapper::add(const RenderObject* renderer, Fingerprint fingerprint) void FastTextAutosizer::FingerprintMapper::add(const RenderObject* renderer, Fingerprint fingerprint)
{ {
remove(renderer);
m_fingerprints.set(renderer, fingerprint); m_fingerprints.set(renderer, fingerprint);
#ifndef NDEBUG
assertMapsAreConsistent();
#endif
} }
void FastTextAutosizer::FingerprintMapper::addTentativeClusterRoot(const RenderBlock* block, Fingerprint fingerprint) void FastTextAutosizer::FingerprintMapper::addTentativeClusterRoot(const RenderBlock* block, Fingerprint fingerprint)
...@@ -672,6 +694,9 @@ void FastTextAutosizer::FingerprintMapper::addTentativeClusterRoot(const RenderB ...@@ -672,6 +694,9 @@ void FastTextAutosizer::FingerprintMapper::addTentativeClusterRoot(const RenderB
if (addResult.isNewEntry) if (addResult.isNewEntry)
addResult.storedValue->value = adoptPtr(new BlockSet); addResult.storedValue->value = adoptPtr(new BlockSet);
addResult.storedValue->value->add(block); addResult.storedValue->value->add(block);
#ifndef NDEBUG
assertMapsAreConsistent();
#endif
} }
void FastTextAutosizer::FingerprintMapper::remove(const RenderObject* renderer) void FastTextAutosizer::FingerprintMapper::remove(const RenderObject* renderer)
...@@ -688,6 +713,9 @@ void FastTextAutosizer::FingerprintMapper::remove(const RenderObject* renderer) ...@@ -688,6 +713,9 @@ void FastTextAutosizer::FingerprintMapper::remove(const RenderObject* renderer)
blocks.remove(toRenderBlock(renderer)); blocks.remove(toRenderBlock(renderer));
if (blocks.isEmpty()) if (blocks.isEmpty())
m_blocksForFingerprint.remove(blocksIter); m_blocksForFingerprint.remove(blocksIter);
#ifndef NDEBUG
assertMapsAreConsistent();
#endif
} }
FastTextAutosizer::Fingerprint FastTextAutosizer::FingerprintMapper::get(const RenderObject* renderer) FastTextAutosizer::Fingerprint FastTextAutosizer::FingerprintMapper::get(const RenderObject* renderer)
......
...@@ -177,6 +177,9 @@ private: ...@@ -177,6 +177,9 @@ private:
FingerprintMap m_fingerprints; FingerprintMap m_fingerprints;
ReverseFingerprintMap m_blocksForFingerprint; ReverseFingerprintMap m_blocksForFingerprint;
#ifndef NDEBUG
void assertMapsAreConsistent();
#endif
}; };
explicit FastTextAutosizer(const Document*); explicit FastTextAutosizer(const Document*);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment