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

Side by Side Diff: url/gurl.h

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 unified diff | Download patch
« no previous file with comments | « no previous file | url/gurl.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef URL_GURL_H_ 5 #ifndef URL_GURL_H_
6 #define URL_GURL_H_ 6 #define URL_GURL_H_
7 7
8 #include <stddef.h> 8 #include <stddef.h>
9 9
10 #include <iosfwd> 10 #include <iosfwd>
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 public: 47 public:
48 typedef url::StringPieceReplacements<std::string> Replacements; 48 typedef url::StringPieceReplacements<std::string> Replacements;
49 typedef url::StringPieceReplacements<base::string16> ReplacementsW; 49 typedef url::StringPieceReplacements<base::string16> ReplacementsW;
50 50
51 // Creates an empty, invalid URL. 51 // Creates an empty, invalid URL.
52 GURL(); 52 GURL();
53 53
54 // Copy construction is relatively inexpensive, with most of the time going 54 // Copy construction is relatively inexpensive, with most of the time going
55 // to reallocating the string. It does not re-parse. 55 // to reallocating the string. It does not re-parse.
56 GURL(const GURL& other); 56 GURL(const GURL& other);
57 GURL(GURL&& other);
57 58
58 // The strings to this contructor should be UTF-8 / UTF-16. 59 // The strings to this contructor should be UTF-8 / UTF-16.
59 explicit GURL(base::StringPiece url_string); 60 explicit GURL(base::StringPiece url_string);
60 explicit GURL(base::StringPiece16 url_string); 61 explicit GURL(base::StringPiece16 url_string);
61 62
62 // Constructor for URLs that have already been parsed and canonicalized. This 63 // Constructor for URLs that have already been parsed and canonicalized. This
63 // is used for conversions from KURL, for example. The caller must supply all 64 // is used for conversions from KURL, for example. The caller must supply all
64 // information associated with the URL, which must be correct and consistent. 65 // information associated with the URL, which must be correct and consistent.
65 GURL(const char* canonical_spec, 66 GURL(const char* canonical_spec,
66 size_t canonical_spec_len, 67 size_t canonical_spec_len,
67 const url::Parsed& parsed, 68 const url::Parsed& parsed,
68 bool is_valid); 69 bool is_valid);
69 // Notice that we take the canonical_spec by value so that we can convert 70 // Notice that we take the canonical_spec by value so that we can convert
70 // from WebURL without copying the string. When we call this constructor 71 // from WebURL without copying the string. When we call this constructor
71 // we pass in a temporary std::string, which lets the compiler skip the 72 // we pass in a temporary std::string, which lets the compiler skip the
72 // copy and just move the std::string into the function argument. In the 73 // copy and just move the std::string into the function argument. In the
73 // implementation, we use std::move to move the data into the GURL itself, 74 // implementation, we use std::move to move the data into the GURL itself,
74 // which means we end up with zero copies. 75 // which means we end up with zero copies.
75 GURL(std::string canonical_spec, const url::Parsed& parsed, bool is_valid); 76 GURL(std::string canonical_spec, const url::Parsed& parsed, bool is_valid);
76 77
77 ~GURL(); 78 ~GURL();
78 79
79 GURL& operator=(GURL other); 80 GURL& operator=(const GURL& other);
81 GURL& operator=(GURL&& other);
80 82
81 // Returns true when this object represents a valid parsed URL. When not 83 // Returns true when this object represents a valid parsed URL. When not
82 // valid, other functions will still succeed, but you will not get canonical 84 // valid, other functions will still succeed, but you will not get canonical
83 // data out in the format you may be expecting. Instead, we keep something 85 // data out in the format you may be expecting. Instead, we keep something
84 // "reasonable looking" so that the user can see how it's busted if 86 // "reasonable looking" so that the user can see how it's busted if
85 // displayed to them. 87 // displayed to them.
86 bool is_valid() const { 88 bool is_valid() const {
87 return is_valid_; 89 return is_valid_;
88 } 90 }
89 91
(...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after
465 URL_EXPORT bool operator==(const GURL& x, const GURL& y); 467 URL_EXPORT bool operator==(const GURL& x, const GURL& y);
466 URL_EXPORT bool operator!=(const GURL& x, const GURL& y); 468 URL_EXPORT bool operator!=(const GURL& x, const GURL& y);
467 469
468 // Equality operator for comparing raw spec_. This should be used in place of 470 // Equality operator for comparing raw spec_. This should be used in place of
469 // url == GURL(spec) where |spec| is known (i.e. constants). This is to prevent 471 // url == GURL(spec) where |spec| is known (i.e. constants). This is to prevent
470 // needlessly re-parsing |spec| into a temporary GURL. 472 // needlessly re-parsing |spec| into a temporary GURL.
471 URL_EXPORT bool operator==(const GURL& x, const base::StringPiece& spec); 473 URL_EXPORT bool operator==(const GURL& x, const base::StringPiece& spec);
472 URL_EXPORT bool operator!=(const GURL& x, const base::StringPiece& spec); 474 URL_EXPORT bool operator!=(const GURL& x, const base::StringPiece& spec);
473 475
474 #endif // URL_GURL_H_ 476 #endif // URL_GURL_H_
OLDNEW
« no previous file with comments | « no previous file | url/gurl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698