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

Side by Side Diff: base/values.cc

Issue 7618021: base: Fix the TODO in ListValue::Remove(). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix chromeos Created 9 years, 4 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 | « base/values.h ('k') | base/values_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/values.h" 5 #include "base/values.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/string_util.h" 8 #include "base/string_util.h"
9 #include "base/utf_string_conversions.h" 9 #include "base/utf_string_conversions.h"
10 10
(...skipping 800 matching lines...) Expand 10 before | Expand all | Expand 10 after
811 811
812 if (out_value) 812 if (out_value)
813 *out_value = list_[index]; 813 *out_value = list_[index];
814 else 814 else
815 delete list_[index]; 815 delete list_[index];
816 816
817 list_.erase(list_.begin() + index); 817 list_.erase(list_.begin() + index);
818 return true; 818 return true;
819 } 819 }
820 820
821 int ListValue::Remove(const Value& value) { 821 bool ListValue::Remove(const Value& value, size_t* index) {
822 for (ValueVector::iterator i(list_.begin()); i != list_.end(); ++i) { 822 for (ValueVector::iterator i(list_.begin()); i != list_.end(); ++i) {
823 if ((*i)->Equals(&value)) { 823 if ((*i)->Equals(&value)) {
824 size_t index = i - list_.begin(); 824 size_t previous_index = i - list_.begin();
825 delete *i; 825 delete *i;
826 list_.erase(i); 826 list_.erase(i);
827 827
828 // TODO(anyone): Returning a signed int type here is just wrong. 828 if (index)
829 // Change this interface to return a size_t. 829 *index = previous_index;
830 DCHECK(index <= INT_MAX); 830 return true;
831 int return_index = static_cast<int>(index);
832 return return_index;
833 } 831 }
834 } 832 }
835 return -1; 833 return false;
836 } 834 }
837 835
838 void ListValue::Append(Value* in_value) { 836 void ListValue::Append(Value* in_value) {
839 DCHECK(in_value); 837 DCHECK(in_value);
840 list_.push_back(in_value); 838 list_.push_back(in_value);
841 } 839 }
842 840
843 bool ListValue::AppendIfNotPresent(Value* in_value) { 841 bool ListValue::AppendIfNotPresent(Value* in_value) {
844 DCHECK(in_value); 842 DCHECK(in_value);
845 for (ValueVector::const_iterator i(list_.begin()); i != list_.end(); ++i) { 843 for (ValueVector::const_iterator i(list_.begin()); i != list_.end(); ++i) {
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
898 if (lhs_it != end() || rhs_it != other_list->end()) 896 if (lhs_it != end() || rhs_it != other_list->end())
899 return false; 897 return false;
900 898
901 return true; 899 return true;
902 } 900 }
903 901
904 ValueSerializer::~ValueSerializer() { 902 ValueSerializer::~ValueSerializer() {
905 } 903 }
906 904
907 } // namespace base 905 } // namespace base
OLDNEW
« no previous file with comments | « base/values.h ('k') | base/values_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698