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

Unified Diff: content/browser/service_worker/service_worker_url_request_job.cc

Issue 2690333003: service worker: Optimize response header creation. (Closed)
Patch Set: fix auto Created 3 years, 10 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 | content/browser/service_worker/service_worker_url_request_job_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/browser/service_worker/service_worker_url_request_job.cc
diff --git a/content/browser/service_worker/service_worker_url_request_job.cc b/content/browser/service_worker/service_worker_url_request_job.cc
index d794db26b767e799f4ebcd2b165027076dd99575..45c64a83a9d7be29f278ea9d012cbd4faf43a3e6 100644
--- a/content/browser/service_worker/service_worker_url_request_job.cc
+++ b/content/browser/service_worker/service_worker_url_request_job.cc
@@ -679,20 +679,20 @@ void ServiceWorkerURLRequestJob::CreateResponseHeader(
const ServiceWorkerHeaderMap& headers) {
// TODO(kinuko): If the response has an identifier to on-disk cache entry,
// pull response header from the disk.
- std::string status_line(
- base::StringPrintf("HTTP/1.1 %d %s", status_code, status_text.c_str()));
- status_line.push_back('\0');
- http_response_headers_ = new net::HttpResponseHeaders(status_line);
- for (ServiceWorkerHeaderMap::const_iterator it = headers.begin();
- it != headers.end();
- ++it) {
- std::string header;
- header.reserve(it->first.size() + 2 + it->second.size());
- header.append(it->first);
- header.append(": ");
- header.append(it->second);
- http_response_headers_->AddHeader(header);
+
+ // Build a string instead of using HttpResponseHeaders::AddHeader on
+ // each header, since AddHeader has O(n^2) performance.
+ std::string buf(base::StringPrintf("HTTP/1.1 %d %s\r\n", status_code,
+ status_text.c_str()));
+ for (const auto& item : headers) {
+ buf.append(item.first);
+ buf.append(": ");
+ buf.append(item.second);
+ buf.append("\r\n");
}
+ buf.append("\r\n");
+ http_response_headers_ = new net::HttpResponseHeaders(
+ net::HttpUtil::AssembleRawHeaders(buf.c_str(), buf.size()));
}
void ServiceWorkerURLRequestJob::CommitResponseHeader() {
« no previous file with comments | « no previous file | content/browser/service_worker/service_worker_url_request_job_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698