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

Unified Diff: base/values.cc

Issue 2815303002: Improve performance of base::ListValue::Append* (Closed)
Patch Set: Rebase Created 3 years, 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/values.cc
diff --git a/base/values.cc b/base/values.cc
index 765cf90ec3136e8f7dbd276c701c31995d04ffb2..4c7421dc3cdae503d8c317c907975fbefdd59ebe 100644
--- a/base/values.cc
+++ b/base/values.cc
@@ -1076,14 +1076,10 @@ bool ListValue::Set(size_t index, std::unique_ptr<Value> in_value) {
if (!in_value)
return false;
- if (index >= list_->size()) {
- // Pad out any intermediate indexes with null settings
- while (index > list_->size())
- Append(MakeUnique<Value>());
- Append(std::move(in_value));
- } else {
- (*list_)[index] = std::move(*in_value);
- }
+ if (index >= list_->size())
+ list_->resize(index + 1);
+
+ (*list_)[index] = std::move(*in_value);
return true;
}
@@ -1234,37 +1230,35 @@ void ListValue::Append(std::unique_ptr<Value> in_value) {
}
void ListValue::AppendBoolean(bool in_value) {
- Append(MakeUnique<Value>(in_value));
+ list_->emplace_back(in_value);
}
void ListValue::AppendInteger(int in_value) {
- Append(MakeUnique<Value>(in_value));
+ list_->emplace_back(in_value);
}
void ListValue::AppendDouble(double in_value) {
- Append(MakeUnique<Value>(in_value));
+ list_->emplace_back(in_value);
}
void ListValue::AppendString(StringPiece in_value) {
- Append(MakeUnique<Value>(in_value));
+ list_->emplace_back(in_value);
}
void ListValue::AppendString(const string16& in_value) {
- Append(MakeUnique<Value>(in_value));
+ list_->emplace_back(in_value);
}
void ListValue::AppendStrings(const std::vector<std::string>& in_values) {
- for (std::vector<std::string>::const_iterator it = in_values.begin();
- it != in_values.end(); ++it) {
- AppendString(*it);
- }
+ list_->reserve(list_->size() + in_values.size());
+ for (const auto& in_value : in_values)
+ list_->emplace_back(in_value);
}
void ListValue::AppendStrings(const std::vector<string16>& in_values) {
- for (std::vector<string16>::const_iterator it = in_values.begin();
- it != in_values.end(); ++it) {
- AppendString(*it);
- }
+ list_->reserve(list_->size() + in_values.size());
+ for (const auto& in_value : in_values)
+ list_->emplace_back(in_value);
}
bool ListValue::AppendIfNotPresent(std::unique_ptr<Value> in_value) {
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698