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

Unified Diff: net/spdy/spdy_http_utils.cc

Issue 996483002: Improve code with early returns. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 9 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: net/spdy/spdy_http_utils.cc
diff --git a/net/spdy/spdy_http_utils.cc b/net/spdy/spdy_http_utils.cc
index c604880473c7c41666bf79e5b8a87e52033ceaf1..dcd120fd77dbcd1f78766b586cb020edb1cf3677 100644
--- a/net/spdy/spdy_http_utils.cc
+++ b/net/spdy/spdy_http_utils.cc
@@ -183,28 +183,22 @@ NET_EXPORT_PRIVATE RequestPriority ConvertSpdyPriorityToRequestPriority(
GURL GetUrlFromHeaderBlock(const SpdyHeaderBlock& headers,
SpdyMajorVersion protocol_version,
bool pushed) {
- const char* scheme_header = protocol_version >= SPDY3 ? ":scheme" : "scheme";
- const char* host_header = protocol_version >= SPDY4 ? ":authority" :
- (protocol_version >= SPDY3 ? ":host" : "host");
- const char* path_header = protocol_version >= SPDY3 ? ":path" : "url";
-
- std::string scheme;
- std::string host_port;
- std::string path;
- SpdyHeaderBlock::const_iterator it;
- it = headers.find(scheme_header);
- if (it != headers.end())
- scheme = it->second;
- it = headers.find(host_header);
- if (it != headers.end())
- host_port = it->second;
- it = headers.find(path_header);
- if (it != headers.end())
- path = it->second;
-
- std::string url = (scheme.empty() || host_port.empty() || path.empty())
- ? std::string()
- : scheme + "://" + host_port + path;
+ DCHECK_LE(SPDY3, protocol_version);
+ SpdyHeaderBlock::const_iterator it = headers.find(":scheme");
+ if (it == headers.end())
+ return GURL();
+ std::string url = it->second;
+ url.append("://");
+
+ it = headers.find(protocol_version >= SPDY4 ? ":authority" : ":host");
+ if (it == headers.end())
+ return GURL();
+ url.append(it->second);
+
+ it = headers.find(":path");
+ if (it == headers.end())
+ return GURL();
+ url.append(it->second);
return GURL(url);
}
« 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