From 8093a31b1f54b0f3f4248fa52e95fe80bcd8c1dd Mon Sep 17 00:00:00 2001 From: "cjhopman@chromium.org" Date: Thu, 24 Oct 2013 21:56:33 +0000 Subject: Use copy-swap idiom for GURL::operator= All the work to correctly handle ownership and internal state of GURL is already done by the copy-constructor, destructor, and GURL::Swap. Repeating that work for GURL::operator= is just another place where we might get it wrong. BUG=309975 Review URL: https://codereview.chromium.org/30693010 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@230829 0039d316-1c4b-4281-b951-d872f2087c98 --- url/gurl.cc | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) (limited to 'url/gurl.cc') diff --git a/url/gurl.cc b/url/gurl.cc index 60850e6..15de85a 100644 --- a/url/gurl.cc +++ b/url/gurl.cc @@ -167,18 +167,8 @@ void GURL::InitializeFromCanonicalSpec() { GURL::~GURL() { } -GURL& GURL::operator=(const GURL& other) { - if (&other == this) - return *this; - - spec_ = other.spec_; - is_valid_ = other.is_valid_; - parsed_ = other.parsed_; - inner_url_.reset(NULL); - if (other.inner_url_) - inner_url_.reset(new GURL(*other.inner_url_)); - // Valid filesystem urls should always have an inner_url_. - DCHECK(!is_valid_ || !SchemeIsFileSystem() || inner_url_); +GURL& GURL::operator=(GURL other) { + Swap(&other); return *this; } -- cgit v1.1