summaryrefslogtreecommitdiffstats
path: root/url
diff options
context:
space:
mode:
authorabarth@chromium.org <abarth@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-07-26 13:30:09 +0000
committerabarth@chromium.org <abarth@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-07-26 13:30:09 +0000
commit19b61f97d21751a7e81bd2b52b26e3823c30669d (patch)
treefc49feee0f87c47824d1b49d179af691e0e3655c /url
parent5b54b978c3c0b001f468e4712ed284452982d7b5 (diff)
downloadchromium_src-19b61f97d21751a7e81bd2b52b26e3823c30669d.zip
chromium_src-19b61f97d21751a7e81bd2b52b26e3823c30669d.tar.gz
chromium_src-19b61f97d21751a7e81bd2b52b26e3823c30669d.tar.bz2
Allow efficient WebURL -> GURL conversions
This CL adds a constructor to GURL that takes a std::string instead of a char* and a length. This constructor allows Blink to produce a temporary std::string containing the URL's spec that we can move directly into the GURL, avoiding a copy. Once I update Blink, this constructor will help us avoid spending 5% of our total time rendering http://sina.com.cn on KURL -> GURL conversions. R=brettw BUG=261412 Review URL: https://chromiumcodereview.appspot.com/20127002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@213885 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'url')
-rw-r--r--url/gurl.cc17
-rw-r--r--url/gurl.h10
2 files changed, 25 insertions, 2 deletions
diff --git a/url/gurl.cc b/url/gurl.cc
index 3dd8463..09b8abb 100644
--- a/url/gurl.cc
+++ b/url/gurl.cc
@@ -116,6 +116,19 @@ GURL::GURL(const char* canonical_spec, size_t canonical_spec_len,
is_valid_(is_valid),
parsed_(parsed),
inner_url_(NULL) {
+ InitializeFromCanonicalSpec();
+}
+
+GURL::GURL(std::string canonical_spec,
+ const url_parse::Parsed& parsed, bool is_valid)
+ : is_valid_(is_valid),
+ parsed_(parsed),
+ inner_url_(NULL) {
+ spec_.swap(canonical_spec);
+ InitializeFromCanonicalSpec();
+}
+
+void GURL::InitializeFromCanonicalSpec() {
if (is_valid_ && SchemeIsFileSystem()) {
inner_url_ =
new GURL(spec_.data(), parsed_.Length(), *parsed_.inner_parsed(), true);
@@ -127,9 +140,9 @@ GURL::GURL(const char* canonical_spec, size_t canonical_spec_len,
// and we can't always canonicalize then reproducabely.
if (is_valid_) {
url_parse::Component scheme;
- if (!url_util::FindAndCompareScheme(canonical_spec, canonical_spec_len,
+ if (!url_util::FindAndCompareScheme(spec_.data(), spec_.length(),
"filesystem", &scheme) ||
- scheme.begin == parsed.scheme.begin) {
+ scheme.begin == parsed_.scheme.begin) {
// We can't do this check on the inner_url of a filesystem URL, as
// canonical_spec actually points to the start of the outer URL, so we'd
// end up with infinite recursion in this constructor.
diff --git a/url/gurl.h b/url/gurl.h
index 6e58249..da5f736 100644
--- a/url/gurl.h
+++ b/url/gurl.h
@@ -41,6 +41,14 @@ class URL_EXPORT GURL {
// information associated with the URL, which must be correct and consistent.
GURL(const char* canonical_spec, size_t canonical_spec_len,
const url_parse::Parsed& parsed, bool is_valid);
+ // Notice that we take the canonical_spec by value so that we can convert
+ // from WebURL without copying the string. When we call this constructor
+ // we pass in a temporary std::string, which lets the compiler skip the
+ // copy and just move the std::string into the function argument. In the
+ // implementation, we use swap to move the data into the GURL itself,
+ // which means we end up with zero copies.
+ GURL(std::string canonical_spec,
+ const url_parse::Parsed& parsed, bool is_valid);
~GURL();
@@ -335,6 +343,8 @@ class URL_EXPORT GURL {
}
private:
+ void InitializeFromCanonicalSpec();
+
// Returns the substring of the input identified by the given component.
std::string ComponentString(const url_parse::Component& comp) const {
if (comp.len <= 0)