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

Side by Side Diff: url/origin.cc

Issue 2561363002: Add std::string constructors for Origin/SchemeHostPort to reduce copies (Closed)
Patch Set: fix content_unittests Created 4 years 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 | « url/origin.h ('k') | url/origin_unittest.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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 #include "url/origin.h" 5 #include "url/origin.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 #include <string.h> 8 #include <string.h>
9 9
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 } 78 }
79 79
80 unique_ = tuple_.IsInvalid(); 80 unique_ = tuple_.IsInvalid();
81 } 81 }
82 82
83 Origin::Origin(base::StringPiece scheme, 83 Origin::Origin(base::StringPiece scheme,
84 base::StringPiece host, 84 base::StringPiece host,
85 uint16_t port, 85 uint16_t port,
86 base::StringPiece suborigin, 86 base::StringPiece suborigin,
87 SchemeHostPort::ConstructPolicy policy) 87 SchemeHostPort::ConstructPolicy policy)
88 : tuple_(scheme, host, port, policy) { 88 : tuple_(scheme.as_string(), host.as_string(), port, policy) {
89 unique_ = tuple_.IsInvalid(); 89 unique_ = tuple_.IsInvalid();
90 suborigin_ = suborigin.as_string(); 90 suborigin_ = suborigin.as_string();
91 } 91 }
92 92
93 Origin::Origin(std::string scheme,
94 std::string host,
95 uint16_t port,
96 std::string suborigin,
97 SchemeHostPort::ConstructPolicy policy)
98 : tuple_(std::move(scheme), std::move(host), port, policy) {
99 unique_ = tuple_.IsInvalid();
100 suborigin_ = std::move(suborigin);
101 }
102
93 Origin::~Origin() { 103 Origin::~Origin() {
94 } 104 }
95 105
96 // static 106 // static
97 Origin Origin::UnsafelyCreateOriginWithoutNormalization( 107 Origin Origin::UnsafelyCreateOriginWithoutNormalization(
98 base::StringPiece scheme, 108 base::StringPiece scheme,
99 base::StringPiece host, 109 base::StringPiece host,
100 uint16_t port) { 110 uint16_t port) {
101 return Origin(scheme, host, port, "", SchemeHostPort::CHECK_CANONICALIZATION); 111 return Origin(scheme, host, port, "", SchemeHostPort::CHECK_CANONICALIZATION);
102 } 112 }
103 113
104 Origin Origin::CreateFromNormalizedTuple(base::StringPiece scheme,
105 base::StringPiece host,
106 uint16_t port) {
107 return CreateFromNormalizedTupleWithSuborigin(scheme, host, port, "");
108 }
109
110 Origin Origin::CreateFromNormalizedTupleWithSuborigin( 114 Origin Origin::CreateFromNormalizedTupleWithSuborigin(
111 base::StringPiece scheme, 115 std::string scheme,
112 base::StringPiece host, 116 std::string host,
113 uint16_t port, 117 uint16_t port,
114 base::StringPiece suborigin) { 118 std::string suborigin) {
115 return Origin(scheme, host, port, suborigin, 119 return Origin(std::move(scheme), std::move(host), port, std::move(suborigin),
116 SchemeHostPort::ALREADY_CANONICALIZED); 120 SchemeHostPort::ALREADY_CANONICALIZED);
117 } 121 }
118 122
119 std::string Origin::Serialize() const { 123 std::string Origin::Serialize() const {
120 if (unique()) 124 if (unique())
121 return "null"; 125 return "null";
122 126
123 if (scheme() == kFileScheme) 127 if (scheme() == kFileScheme)
124 return "file://"; 128 return "file://";
125 129
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 182
179 bool IsSameOriginWith(const GURL& a, const GURL& b) { 183 bool IsSameOriginWith(const GURL& a, const GURL& b) {
180 return Origin(a).IsSameOriginWith(Origin(b)); 184 return Origin(a).IsSameOriginWith(Origin(b));
181 } 185 }
182 186
183 bool IsSamePhysicalOriginWith(const GURL& a, const GURL& b) { 187 bool IsSamePhysicalOriginWith(const GURL& a, const GURL& b) {
184 return Origin(a).IsSamePhysicalOriginWith(Origin(b)); 188 return Origin(a).IsSamePhysicalOriginWith(Origin(b));
185 } 189 }
186 190
187 } // namespace url 191 } // namespace url
OLDNEW
« no previous file with comments | « url/origin.h ('k') | url/origin_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698