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

Side by Side 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, 9 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/core/rendering/FastTextAutosizer.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2013 Google Inc. All rights reserved. 2 * Copyright (C) 2013 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 641 matching lines...) Expand 10 before | Expand all | Expand 10 after
652 652
653 return false; 653 return false;
654 } 654 }
655 655
656 FastTextAutosizer::Cluster* FastTextAutosizer::currentCluster() const 656 FastTextAutosizer::Cluster* FastTextAutosizer::currentCluster() const
657 { 657 {
658 ASSERT(!m_clusterStack.isEmpty()); 658 ASSERT(!m_clusterStack.isEmpty());
659 return m_clusterStack.last().get(); 659 return m_clusterStack.last().get();
660 } 660 }
661 661
662 #ifndef NDEBUG
663 bool FastTextAutosizer::FingerprintMapper::mapsAreConsistent()
664 {
665 // For each fingerprint -> block mapping in m_blocksForFingerprint we should have an associated
666 // map from block -> fingerprint in m_fingerprints.
667 ReverseFingerprintMap::iterator end = m_blocksForFingerprint.end();
668 for (ReverseFingerprintMap::iterator fingerprintIt = m_blocksForFingerprint. begin(); fingerprintIt != end; ++fingerprintIt) {
669 Fingerprint fingerprint = fingerprintIt->key;
670 BlockSet* blocks = fingerprintIt->value.get();
671 for (BlockSet::iterator blockIt = blocks->begin(); blockIt != blocks->en d(); ++blockIt) {
672 const RenderBlock* block = (*blockIt);
673 ASSERT(m_fingerprints.get(block) == fingerprint);
674 }
675 }
676
677 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
678 }
679 #endif
680
662 void FastTextAutosizer::FingerprintMapper::add(const RenderObject* renderer, Fin gerprint fingerprint) 681 void FastTextAutosizer::FingerprintMapper::add(const RenderObject* renderer, Fin gerprint fingerprint)
663 { 682 {
683 // Make sure to remove any existing fingerprint mapping for this renderer.
684 Fingerprint oldFingerprint = m_fingerprints.get(renderer);
685 if (oldFingerprint && renderer->isRenderBlock()) {
686 ReverseFingerprintMap::iterator blocksIter = m_blocksForFingerprint.find (oldFingerprint);
687 if (blocksIter != m_blocksForFingerprint.end())
688 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
689 }
690
664 m_fingerprints.set(renderer, fingerprint); 691 m_fingerprints.set(renderer, fingerprint);
692
693 ASSERT(mapsAreConsistent());
665 } 694 }
666 695
667 void FastTextAutosizer::FingerprintMapper::addTentativeClusterRoot(const RenderB lock* block, Fingerprint fingerprint) 696 void FastTextAutosizer::FingerprintMapper::addTentativeClusterRoot(const RenderB lock* block, Fingerprint fingerprint)
668 { 697 {
669 add(block, fingerprint); 698 add(block, fingerprint);
670 699
671 ReverseFingerprintMap::AddResult addResult = m_blocksForFingerprint.add(fing erprint, PassOwnPtr<BlockSet>()); 700 ReverseFingerprintMap::AddResult addResult = m_blocksForFingerprint.add(fing erprint, PassOwnPtr<BlockSet>());
672 if (addResult.isNewEntry) 701 if (addResult.isNewEntry)
673 addResult.storedValue->value = adoptPtr(new BlockSet); 702 addResult.storedValue->value = adoptPtr(new BlockSet);
674 addResult.storedValue->value->add(block); 703 addResult.storedValue->value->add(block);
704 ASSERT(mapsAreConsistent());
675 } 705 }
676 706
677 void FastTextAutosizer::FingerprintMapper::remove(const RenderObject* renderer) 707 void FastTextAutosizer::FingerprintMapper::remove(const RenderObject* renderer)
678 { 708 {
679 Fingerprint fingerprint = m_fingerprints.take(renderer); 709 Fingerprint fingerprint = m_fingerprints.take(renderer);
680 if (!fingerprint || !renderer->isRenderBlock()) 710 if (!fingerprint || !renderer->isRenderBlock())
681 return; 711 return;
682 712
683 ReverseFingerprintMap::iterator blocksIter = m_blocksForFingerprint.find(fin gerprint); 713 ReverseFingerprintMap::iterator blocksIter = m_blocksForFingerprint.find(fin gerprint);
684 if (blocksIter == m_blocksForFingerprint.end()) 714 if (blocksIter == m_blocksForFingerprint.end())
685 return; 715 return;
686 716
687 BlockSet& blocks = *blocksIter->value; 717 BlockSet& blocks = *blocksIter->value;
688 blocks.remove(toRenderBlock(renderer)); 718 blocks.remove(toRenderBlock(renderer));
689 if (blocks.isEmpty()) 719 if (blocks.isEmpty())
690 m_blocksForFingerprint.remove(blocksIter); 720 m_blocksForFingerprint.remove(blocksIter);
721 ASSERT(mapsAreConsistent());
691 } 722 }
692 723
693 FastTextAutosizer::Fingerprint FastTextAutosizer::FingerprintMapper::get(const R enderObject* renderer) 724 FastTextAutosizer::Fingerprint FastTextAutosizer::FingerprintMapper::get(const R enderObject* renderer)
694 { 725 {
695 return m_fingerprints.get(renderer); 726 return m_fingerprints.get(renderer);
696 } 727 }
697 728
698 FastTextAutosizer::BlockSet& FastTextAutosizer::FingerprintMapper::getTentativeC lusterRoots(Fingerprint fingerprint) 729 FastTextAutosizer::BlockSet& FastTextAutosizer::FingerprintMapper::getTentativeC lusterRoots(Fingerprint fingerprint)
699 { 730 {
700 return *m_blocksForFingerprint.get(fingerprint); 731 return *m_blocksForFingerprint.get(fingerprint);
(...skipping 27 matching lines...) Expand all
728 m_textAutosizer = 0; 759 m_textAutosizer = 0;
729 } 760 }
730 761
731 FastTextAutosizer::LayoutScope::~LayoutScope() 762 FastTextAutosizer::LayoutScope::~LayoutScope()
732 { 763 {
733 if (m_textAutosizer) 764 if (m_textAutosizer)
734 m_textAutosizer->endLayout(m_block); 765 m_textAutosizer->endLayout(m_block);
735 } 766 }
736 767
737 } // namespace WebCore 768 } // namespace WebCore
OLDNEW
« 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