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

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: Address reviewer comments 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 void FastTextAutosizer::FingerprintMapper::assertMapsAreConsistent()
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 #endif
678
662 void FastTextAutosizer::FingerprintMapper::add(const RenderObject* renderer, Fin gerprint fingerprint) 679 void FastTextAutosizer::FingerprintMapper::add(const RenderObject* renderer, Fin gerprint fingerprint)
663 { 680 {
681 remove(renderer);
682
664 m_fingerprints.set(renderer, fingerprint); 683 m_fingerprints.set(renderer, fingerprint);
684 #ifndef NDEBUG
685 assertMapsAreConsistent();
686 #endif
665 } 687 }
666 688
667 void FastTextAutosizer::FingerprintMapper::addTentativeClusterRoot(const RenderB lock* block, Fingerprint fingerprint) 689 void FastTextAutosizer::FingerprintMapper::addTentativeClusterRoot(const RenderB lock* block, Fingerprint fingerprint)
668 { 690 {
669 add(block, fingerprint); 691 add(block, fingerprint);
670 692
671 ReverseFingerprintMap::AddResult addResult = m_blocksForFingerprint.add(fing erprint, PassOwnPtr<BlockSet>()); 693 ReverseFingerprintMap::AddResult addResult = m_blocksForFingerprint.add(fing erprint, PassOwnPtr<BlockSet>());
672 if (addResult.isNewEntry) 694 if (addResult.isNewEntry)
673 addResult.storedValue->value = adoptPtr(new BlockSet); 695 addResult.storedValue->value = adoptPtr(new BlockSet);
674 addResult.storedValue->value->add(block); 696 addResult.storedValue->value->add(block);
697 #ifndef NDEBUG
698 assertMapsAreConsistent();
699 #endif
675 } 700 }
676 701
677 void FastTextAutosizer::FingerprintMapper::remove(const RenderObject* renderer) 702 void FastTextAutosizer::FingerprintMapper::remove(const RenderObject* renderer)
678 { 703 {
679 Fingerprint fingerprint = m_fingerprints.take(renderer); 704 Fingerprint fingerprint = m_fingerprints.take(renderer);
680 if (!fingerprint || !renderer->isRenderBlock()) 705 if (!fingerprint || !renderer->isRenderBlock())
681 return; 706 return;
682 707
683 ReverseFingerprintMap::iterator blocksIter = m_blocksForFingerprint.find(fin gerprint); 708 ReverseFingerprintMap::iterator blocksIter = m_blocksForFingerprint.find(fin gerprint);
684 if (blocksIter == m_blocksForFingerprint.end()) 709 if (blocksIter == m_blocksForFingerprint.end())
685 return; 710 return;
686 711
687 BlockSet& blocks = *blocksIter->value; 712 BlockSet& blocks = *blocksIter->value;
688 blocks.remove(toRenderBlock(renderer)); 713 blocks.remove(toRenderBlock(renderer));
689 if (blocks.isEmpty()) 714 if (blocks.isEmpty())
690 m_blocksForFingerprint.remove(blocksIter); 715 m_blocksForFingerprint.remove(blocksIter);
716 #ifndef NDEBUG
717 assertMapsAreConsistent();
718 #endif
691 } 719 }
692 720
693 FastTextAutosizer::Fingerprint FastTextAutosizer::FingerprintMapper::get(const R enderObject* renderer) 721 FastTextAutosizer::Fingerprint FastTextAutosizer::FingerprintMapper::get(const R enderObject* renderer)
694 { 722 {
695 return m_fingerprints.get(renderer); 723 return m_fingerprints.get(renderer);
696 } 724 }
697 725
698 FastTextAutosizer::BlockSet& FastTextAutosizer::FingerprintMapper::getTentativeC lusterRoots(Fingerprint fingerprint) 726 FastTextAutosizer::BlockSet& FastTextAutosizer::FingerprintMapper::getTentativeC lusterRoots(Fingerprint fingerprint)
699 { 727 {
700 return *m_blocksForFingerprint.get(fingerprint); 728 return *m_blocksForFingerprint.get(fingerprint);
(...skipping 27 matching lines...) Expand all
728 m_textAutosizer = 0; 756 m_textAutosizer = 0;
729 } 757 }
730 758
731 FastTextAutosizer::LayoutScope::~LayoutScope() 759 FastTextAutosizer::LayoutScope::~LayoutScope()
732 { 760 {
733 if (m_textAutosizer) 761 if (m_textAutosizer)
734 m_textAutosizer->endLayout(m_block); 762 m_textAutosizer->endLayout(m_block);
735 } 763 }
736 764
737 } // namespace WebCore 765 } // 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