OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "base/values.h" | 5 #include "base/values.h" |
6 | 6 |
7 #include <string.h> | 7 #include <string.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <cmath> | 10 #include <cmath> |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
166 | 166 |
167 Value::Value(const std::vector<char>& in_blob) : type_(Type::BINARY) { | 167 Value::Value(const std::vector<char>& in_blob) : type_(Type::BINARY) { |
168 binary_value_.Init(in_blob); | 168 binary_value_.Init(in_blob); |
169 } | 169 } |
170 | 170 |
171 Value::Value(std::vector<char>&& in_blob) : type_(Type::BINARY) { | 171 Value::Value(std::vector<char>&& in_blob) : type_(Type::BINARY) { |
172 binary_value_.Init(std::move(in_blob)); | 172 binary_value_.Init(std::move(in_blob)); |
173 } | 173 } |
174 | 174 |
175 Value& Value::operator=(const Value& that) { | 175 Value& Value::operator=(const Value& that) { |
176 if (this != &that) { | 176 if (type_ == that.type_) { |
177 if (type_ == that.type_) { | 177 InternalCopyAssignFromSameType(that); |
178 InternalCopyAssignFromSameType(that); | 178 } else { |
179 } else { | 179 // this is not a self assignment because the type_ doesn't match. |
180 InternalCleanup(); | 180 InternalCleanup(); |
181 InternalCopyConstructFrom(that); | 181 InternalCopyConstructFrom(that); |
182 } | |
183 } | 182 } |
184 | 183 |
185 return *this; | 184 return *this; |
186 } | 185 } |
187 | 186 |
188 Value& Value::operator=(Value&& that) { | 187 Value& Value::operator=(Value&& that) { |
189 if (this != &that) { | 188 if (type_ == that.type_) { |
190 if (type_ == that.type_) { | 189 DCHECK(this != &that) << " attempt to self move assign."; |
191 InternalMoveAssignFromSameType(std::move(that)); | 190 InternalMoveAssignFromSameType(std::move(that)); |
dcheng
2017/03/10 18:40:15
We should just remove the branch entirely if we're
dyaroshev
2017/03/10 18:54:57
Done.
std::variant (http://en.cppreference.com/w/c
| |
192 } else { | 191 } else { |
193 InternalCleanup(); | 192 InternalCleanup(); |
194 InternalMoveConstructFrom(std::move(that)); | 193 InternalMoveConstructFrom(std::move(that)); |
195 } | |
196 } | 194 } |
197 | 195 |
198 return *this; | 196 return *this; |
199 } | 197 } |
200 | 198 |
201 Value::~Value() { | 199 Value::~Value() { |
202 InternalCleanup(); | 200 InternalCleanup(); |
203 } | 201 } |
204 | 202 |
205 // static | 203 // static |
(...skipping 1149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1355 } | 1353 } |
1356 | 1354 |
1357 std::ostream& operator<<(std::ostream& out, const Value::Type& type) { | 1355 std::ostream& operator<<(std::ostream& out, const Value::Type& type) { |
1358 if (static_cast<int>(type) < 0 || | 1356 if (static_cast<int>(type) < 0 || |
1359 static_cast<size_t>(type) >= arraysize(kTypeNames)) | 1357 static_cast<size_t>(type) >= arraysize(kTypeNames)) |
1360 return out << "Invalid Type (index = " << static_cast<int>(type) << ")"; | 1358 return out << "Invalid Type (index = " << static_cast<int>(type) << ")"; |
1361 return out << Value::GetTypeName(type); | 1359 return out << Value::GetTypeName(type); |
1362 } | 1360 } |
1363 | 1361 |
1364 } // namespace base | 1362 } // namespace base |
OLD | NEW |