0

ui/base/models: Reverse the DCHECKs of index.

The way it's written until now is counter-intuitive. This makes it intuitive.

1 - To make sure an int index is in the array range when we are adding we should check for:
index >= 0 && index <= child_count().

So use DCHECK_GE for '>=' and DCHECK_LE for '<=' respectively.

2 - To make sure an int index is in the array range when we are retrieving it from vector we should check for:
index >= 0 && index < child_count().

So use DCHECK_GE for '>=' and DCHECK_LT for '<' respectively.

BUG=None
TEST=app_unittests --gtest_filter=TreeNodeModelTest.*

R=sky@chromium.org

Review URL: http://codereview.chromium.org/7058030

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@87716 0039d316-1c4b-4281-b951-d872f2087c98
This commit is contained in:
tfarina@chromium.org
2011-06-02 22:43:07 +00:00
parent da53133f7d
commit ebb8b251c9

@ -74,8 +74,8 @@ class TreeNode : public TreeModelNode {
// 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);
DCHECK_GE(index, 0);
DCHECK_LE(index, child_count());
// If the node has a parent, remove it from its parent.
NodeType* parent = node->parent_;
if (parent)
@ -116,8 +116,8 @@ class TreeNode : public TreeModelNode {
// Returns the node at |index|.
const NodeType* GetChild(int index) const {
DCHECK_LE(0, index);
DCHECK_GT(child_count(), index);
DCHECK_GE(index, 0);
DCHECK_LT(index, child_count());
return children_[index];
}
NodeType* GetChild(int index) {