diff options
author | sky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-12-01 22:29:29 +0000 |
---|---|---|
committer | sky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-12-01 22:29:29 +0000 |
commit | 37bc9130662cb8e86f2a2999b2323f80ab623821 (patch) | |
tree | 3f80593d37c5f28d969c09186c305406874835d0 /ui/base | |
parent | 4b9f729a0b70ef2d916e718e48e9552dcc3d3e7d (diff) | |
download | chromium_src-37bc9130662cb8e86f2a2999b2323f80ab623821.zip chromium_src-37bc9130662cb8e86f2a2999b2323f80ab623821.tar.gz chromium_src-37bc9130662cb8e86f2a2999b2323f80ab623821.tar.bz2 |
BookmarkModel cleanup. synced_node is now mobile_node and I'm nuking
IsVisible as it's no longer needed. This cl resulted in a ton of
changes, the majority are renames though.
BUG=102714
TEST=covered by tests
Review URL: http://codereview.chromium.org/8759017
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@112558 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/base')
-rw-r--r-- | ui/base/models/tree_node_iterator.h | 38 | ||||
-rw-r--r-- | ui/base/models/tree_node_iterator_unittest.cc | 40 |
2 files changed, 4 insertions, 74 deletions
diff --git a/ui/base/models/tree_node_iterator.h b/ui/base/models/tree_node_iterator.h index 5a05df9..26d6dea 100644 --- a/ui/base/models/tree_node_iterator.h +++ b/ui/base/models/tree_node_iterator.h @@ -23,27 +23,7 @@ namespace ui { template <class NodeType> class TreeNodeIterator { public: - // This contructor accepts an optional filter function |prune| which could be - // used to prune complete branches of the tree. The filter function will be - // evaluated on each tree node and if it evaluates to true the node and all - // its descendants will be skipped by the iterator. - TreeNodeIterator(NodeType* node, bool (*prune)(NodeType*)) - : prune_(prune) { - int index = 0; - - // Move forward through the children list until the first non prunable node. - // This is to satisfy the iterator invariant that the current index in the - // Position at the top of the _positions list must point to a node the - // iterator will be returning. - for (; index < node->child_count(); ++index) - if (!prune || !prune(node->GetChild(index))) - break; - - if (index < node->child_count()) - positions_.push(Position<NodeType>(node, index)); - } - - explicit TreeNodeIterator(NodeType* node) : prune_(NULL) { + explicit TreeNodeIterator(NodeType* node) { if (!node->empty()) positions_.push(Position<NodeType>(node, 0)); } @@ -67,18 +47,9 @@ class TreeNodeIterator { // Iterate over result's children. positions_.push(Position<NodeType>(result, 0)); - // Advance to next valid node by skipping over the pruned nodes and the - // empty Positions. At the end of this loop two cases are possible: - // - the current index of the top() Position points to a valid node - // - the _position list is empty, the iterator has_next() will return false. - while (!positions_.empty()) { - if (positions_.top().index >= positions_.top().node->child_count()) - positions_.pop(); // This Position is all processed, move to the next. - else if (prune_ && - prune_(positions_.top().node->GetChild(positions_.top().index))) - positions_.top().index++; // Prune the branch. - else - break; // Now positioned at the next node to be returned. + while (!positions_.empty() && + positions_.top().index >= positions_.top().node->child_count()) { + positions_.pop(); // This Position is all processed, move to the next. } return result; @@ -95,7 +66,6 @@ class TreeNodeIterator { }; std::stack<Position<NodeType> > positions_; - bool (*prune_)(NodeType*); DISALLOW_COPY_AND_ASSIGN(TreeNodeIterator); }; diff --git a/ui/base/models/tree_node_iterator_unittest.cc b/ui/base/models/tree_node_iterator_unittest.cc index 0aefe4d..13140e9 100644 --- a/ui/base/models/tree_node_iterator_unittest.cc +++ b/ui/base/models/tree_node_iterator_unittest.cc @@ -38,44 +38,4 @@ TEST(TreeNodeIteratorTest, Test) { ASSERT_FALSE(iterator.has_next()); } -static bool PruneOdd(TreeNodeWithValue<int>* node) { - return node->value % 2; -} - -static bool PruneEven(TreeNodeWithValue<int>* node) { - return !(node->value % 2); -} - -// The tree used for testing: -// * + 1 -// + 2 -// + 3 + 4 + 5 -// + 7 - -TEST(TreeNodeIteratorPruneTest, Test) { - TreeNodeWithValue<int> root; - root.Add(new TreeNodeWithValue<int>(1), 0); - root.Add(new TreeNodeWithValue<int>(2), 1); - TreeNodeWithValue<int>* f3 = new TreeNodeWithValue<int>(3); - root.Add(f3, 2); - TreeNodeWithValue<int>* f4 = new TreeNodeWithValue<int>(4); - f3->Add(f4, 0); - f4->Add(new TreeNodeWithValue<int>(5), 0); - f3->Add(new TreeNodeWithValue<int>(7), 1); - - TreeNodeIterator<TreeNodeWithValue<int> > oddIterator(&root, PruneOdd); - ASSERT_TRUE(oddIterator.has_next()); - ASSERT_EQ(2, oddIterator.Next()->value); - ASSERT_FALSE(oddIterator.has_next()); - - TreeNodeIterator<TreeNodeWithValue<int> > evenIterator(&root, PruneEven); - ASSERT_TRUE(evenIterator.has_next()); - ASSERT_EQ(1, evenIterator.Next()->value); - ASSERT_TRUE(evenIterator.has_next()); - ASSERT_EQ(3, evenIterator.Next()->value); - ASSERT_TRUE(evenIterator.has_next()); - ASSERT_EQ(7, evenIterator.Next()->value); - ASSERT_FALSE(evenIterator.has_next()); -} - } // namespace ui |