Index: net/http/http_response_headers.cc |
diff --git a/net/http/http_response_headers.cc b/net/http/http_response_headers.cc |
index 9574b03bc851209f6d53797d7019690fcfd8d76b..8a5ed9834e0985e4b9cd3d8e361b0f94b3271018 100644 |
--- a/net/http/http_response_headers.cc |
+++ b/net/http/http_response_headers.cc |
@@ -168,9 +168,21 @@ HttpResponseHeaders::HttpResponseHeaders(base::PickleIterator* iter) |
void HttpResponseHeaders::Persist(base::Pickle* pickle, |
PersistOptions options) { |
if (options == PERSIST_RAW) { |
+ // To avoid unnecessary copy, we don't call PersistTo here. |
pickle->WriteString(raw_headers_); |
return; // Done. |
} |
+ std::string blob; |
+ PersistTo(options, &blob); |
+ pickle->WriteString(blob); |
+} |
+ |
+void HttpResponseHeaders::PersistTo(PersistOptions options, |
+ std::string* output) { |
+ if (options == PERSIST_RAW) { |
+ *output = raw_headers_; |
+ return; // Done. |
+ } |
HeaderSet filter_headers; |
@@ -193,13 +205,13 @@ void HttpResponseHeaders::Persist(base::Pickle* pickle, |
if ((options & PERSIST_SANS_SECURITY_STATE) == PERSIST_SANS_SECURITY_STATE) |
AddSecurityStateHeaders(&filter_headers); |
- std::string blob; |
- blob.reserve(raw_headers_.size()); |
+ output->clear(); |
+ output->reserve(raw_headers_.size()); |
// This copies the status line w/ terminator null. |
// Note raw_headers_ has embedded nulls instead of \n, |
// so this just copies the first header line. |
- blob.assign(raw_headers_.c_str(), strlen(raw_headers_.c_str()) + 1); |
+ output->assign(raw_headers_.c_str(), strlen(raw_headers_.c_str()) + 1); |
for (size_t i = 0; i < parsed_.size(); ++i) { |
DCHECK(!parsed_[i].is_continuation()); |
@@ -213,15 +225,13 @@ void HttpResponseHeaders::Persist(base::Pickle* pickle, |
base::StringPiece(parsed_[i].name_begin, parsed_[i].name_end)); |
if (filter_headers.find(header_name) == filter_headers.end()) { |
// Make sure there is a null after the value. |
- blob.append(parsed_[i].name_begin, parsed_[k].value_end); |
- blob.push_back('\0'); |
+ output->append(parsed_[i].name_begin, parsed_[k].value_end); |
+ output->push_back('\0'); |
} |
i = k; |
} |
- blob.push_back('\0'); |
- |
- pickle->WriteString(blob); |
+ output->push_back('\0'); |
} |
void HttpResponseHeaders::Update(const HttpResponseHeaders& new_headers) { |