Commit f5a07dab authored by bnc's avatar bnc Committed by Commit bot

Improve code with early returns.

Improve SpdyHttpUtils::GetUrlFromHeaderBlock() implementation with early
returns.  Get rid of a number of temporary variables that were declared too far
from where they were first used.

Also remove SPDY2-specific code, as SPDY2 is no longer supported in Chromium.

Acknowledgements to Daniel Bratell for suggesting to use append instead of
inline operator+ that would create unnecessary temporary strings, see
https://crrev.com/965773002.

BUG=

Review URL: https://codereview.chromium.org/996483002

Cr-Commit-Position: refs/heads/master@{#319784}
parent 176dd4a9
......@@ -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);
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment