diff options
author | tfarina@chromium.org <tfarina@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-06-01 16:05:56 +0000 |
---|---|---|
committer | tfarina@chromium.org <tfarina@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-06-01 16:05:56 +0000 |
commit | 18c917e46ea72f36919d2c62c3054b6f5157fc0f (patch) | |
tree | 042567faf11f9ec5e231b433c0b342c92a0e63a3 /ui | |
parent | 09283b75be2093ef20fa348d5702fa8eca3127ea (diff) | |
download | chromium_src-18c917e46ea72f36919d2c62c3054b6f5157fc0f.zip chromium_src-18c917e46ea72f36919d2c62c3054b6f5157fc0f.tar.gz chromium_src-18c917e46ea72f36919d2c62c3054b6f5157fc0f.tar.bz2 |
ui/base/models: Avoid an unnecessary tmp variable in TreeNode::GetTotalNodeCount().
Unrelated changes:
- Use the member variable |parent_| directly instead of calling the getter accessor |parent()|.
- Tweak some comments. Use node instead of Node to be more consistent.
BUG=None
TEST=out/Debug/app_unittests --gtest_filter=TreeNodeModelTest.GetTotalNodeCount
R=sky@chromium.org
Review URL: http://codereview.chromium.org/6975054
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@87481 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui')
-rw-r--r-- | ui/base/models/tree_node_model.h | 16 |
1 files changed, 7 insertions, 9 deletions
diff --git a/ui/base/models/tree_node_model.h b/ui/base/models/tree_node_model.h index 254cd20..b5fdaa8 100644 --- a/ui/base/models/tree_node_model.h +++ b/ui/base/models/tree_node_model.h @@ -73,20 +73,20 @@ class TreeNode : public TreeModelNode { virtual ~TreeNode() {} - // Adds a TreeNode as a child of this one, at |index|. + // Adds |node| as a child of this one, at |index|. virtual void Add(NodeType* node, int index) { DCHECK(node); DCHECK_LE(0, index); DCHECK_GE(child_count(), index); // If the node has a parent, remove it from its parent. - NodeType* parent = node->parent(); + NodeType* parent = node->parent_; if (parent) parent->Remove(node); node->parent_ = static_cast<NodeType*>(this); children_->insert(children_->begin() + index, node); } - // Remove |node| from this Node and returns it. It's up to the caller to + // Removes |node| from this node and returns it. It's up to the caller to // delete it. virtual NodeType* Remove(NodeType* node) { typename std::vector<NodeType*>::iterator i = @@ -107,14 +107,12 @@ class TreeNode : public TreeModelNode { // Returns the number of children. int child_count() const { return static_cast<int>(children_->size()); } - // Returns the number of all nodes in teh subtree rooted at this node, + // Returns the number of all nodes in the subtree rooted at this node, // including this node. int GetTotalNodeCount() const { int count = 1; // Start with one to include the node itself. - for (size_t i = 0; i < children_->size(); ++i) { - const TreeNode<NodeType>* child = children_[i]; - count += child->GetTotalNodeCount(); - } + for (size_t i = 0; i < children_->size(); ++i) + count += children_[i]->GetTotalNodeCount(); return count; } @@ -129,7 +127,7 @@ class TreeNode : public TreeModelNode { static_cast<const NodeType&>(*this).GetChild(index)); } - // Returns the parent of this object, or NULL if it's the root. + // Returns the parent node, or NULL if this is the root node. const NodeType* parent() const { return parent_; } NodeType* parent() { return parent_; } |