summaryrefslogtreecommitdiffstats
path: root/base
diff options
context:
space:
mode:
authortfarina@chromium.org <tfarina@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-08-13 17:34:31 +0000
committertfarina@chromium.org <tfarina@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-08-13 17:34:31 +0000
commit4fc3c56432cde7d5c938cb75bdfbabd75d9ec755 (patch)
treec75bebaa6ad73888b12e93a24c1880ece01dde96 /base
parent9978b8f0cbac1cd176a6ecac457eb9dacd3ad0f0 (diff)
downloadchromium_src-4fc3c56432cde7d5c938cb75bdfbabd75d9ec755.zip
chromium_src-4fc3c56432cde7d5c938cb75bdfbabd75d9ec755.tar.gz
chromium_src-4fc3c56432cde7d5c938cb75bdfbabd75d9ec755.tar.bz2
base: Fix the TODO in ListValue::Remove().
Change the return type of Remove() to bool, and add a size_t output parameter. BUG=None TEST=None R=evan@chromium.org Review URL: http://codereview.chromium.org/7618021 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@96702 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base')
-rw-r--r--base/values.cc14
-rw-r--r--base/values.h5
-rw-r--r--base/values_unittest.cc4
3 files changed, 12 insertions, 11 deletions
diff --git a/base/values.cc b/base/values.cc
index b215812..7a364bd 100644
--- a/base/values.cc
+++ b/base/values.cc
@@ -818,21 +818,19 @@ bool ListValue::Remove(size_t index, Value** out_value) {
return true;
}
-int ListValue::Remove(const Value& value) {
+bool ListValue::Remove(const Value& value, size_t* index) {
for (ValueVector::iterator i(list_.begin()); i != list_.end(); ++i) {
if ((*i)->Equals(&value)) {
- size_t index = i - list_.begin();
+ size_t previous_index = i - list_.begin();
delete *i;
list_.erase(i);
- // TODO(anyone): Returning a signed int type here is just wrong.
- // Change this interface to return a size_t.
- DCHECK(index <= INT_MAX);
- int return_index = static_cast<int>(index);
- return return_index;
+ if (index)
+ *index = previous_index;
+ return true;
}
}
- return -1;
+ return false;
}
void ListValue::Append(Value* in_value) {
diff --git a/base/values.h b/base/values.h
index 3af36c0..a30791b 100644
--- a/base/values.h
+++ b/base/values.h
@@ -402,8 +402,9 @@ class BASE_EXPORT ListValue : public Value {
bool Remove(size_t index, Value** out_value);
// Removes the first instance of |value| found in the list, if any, and
- // deletes it. Returns the index that it was located at (-1 for not present).
- int Remove(const Value& value);
+ // deletes it. |index| is the location where |value| was found. Returns false
+ // if not found.
+ bool Remove(const Value& value, size_t* index);
// Appends a Value to the end of the list.
void Append(Value* in_value);
diff --git a/base/values_unittest.cc b/base/values_unittest.cc
index b5bcbe1..553e8e1 100644
--- a/base/values_unittest.cc
+++ b/base/values_unittest.cc
@@ -236,7 +236,9 @@ TEST(ValuesTest, ListRemoval) {
DeletionTestValue* value = new DeletionTestValue(&deletion_flag);
list.Append(value);
EXPECT_FALSE(deletion_flag);
- EXPECT_EQ(0, list.Remove(*value));
+ size_t index = 0;
+ list.Remove(*value, &index);
+ EXPECT_EQ(0U, index);
EXPECT_TRUE(deletion_flag);
EXPECT_EQ(0U, list.GetSize());
}