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

Unified Diff: url/gurl.cc

Issue 2737693003: Add move constructors and assignment operators to GURL (Closed)
Patch Set: Created 3 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 | « url/gurl.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: url/gurl.cc
diff --git a/url/gurl.cc b/url/gurl.cc
index c9dad0600b2801f5629ad24a3ce20972b887d7f0..09ab212c5841861e130101f9bdab5ca7e77d0688 100644
--- a/url/gurl.cc
+++ b/url/gurl.cc
@@ -79,6 +79,15 @@ GURL::GURL(const GURL& other)
DCHECK(!is_valid_ || !SchemeIsFileSystem() || inner_url_);
}
+GURL::GURL(GURL&& other)
+ : spec_(std::move(other.spec_)),
+ is_valid_(other.is_valid_),
+ parsed_(other.parsed_),
+ inner_url_(std::move(other.inner_url_)) {
+ other.is_valid_ = false;
+ other.parsed_ = url::Parsed();
+}
+
GURL::GURL(base::StringPiece url_string) {
InitCanonical(url_string, true);
}
@@ -168,8 +177,29 @@ void GURL::InitializeFromCanonicalSpec() {
GURL::~GURL() {
}
-GURL& GURL::operator=(GURL other) {
- Swap(&other);
+GURL& GURL::operator=(const GURL& other) {
+ spec_ = other.spec_;
+ is_valid_ = other.is_valid_;
+ parsed_ = other.parsed_;
+
+ if (!other.inner_url_)
+ inner_url_.reset();
+ else if (inner_url_)
+ *inner_url_ = *other.inner_url_;
+ else
+ inner_url_.reset(new GURL(*other.inner_url_));
+
+ return *this;
+}
+
+GURL& GURL::operator=(GURL&& other) {
+ spec_ = std::move(other.spec_);
+ is_valid_ = other.is_valid_;
+ parsed_ = other.parsed_;
+ inner_url_ = std::move(other.inner_url_);
+
+ other.is_valid_ = false;
+ other.parsed_ = url::Parsed();
return *this;
}
« no previous file with comments | « url/gurl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698