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

Unified Diff: mojo/public/cpp/bindings/array.h

Issue 2136733002: Mojo C++ bindings: add a new mode to generator to use native STL/WTF types (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@67_new
Patch Set: . Created 4 years, 5 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 | « mojo/public/cpp/bindings/BUILD.gn ('k') | mojo/public/cpp/bindings/array_traits_stl.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/public/cpp/bindings/array.h
diff --git a/mojo/public/cpp/bindings/array.h b/mojo/public/cpp/bindings/array.h
index ed8bdb595ae4d02203e6195ef46c765855a56824..a253da1f3954eed84541177cfee46df4c17a7dfa 100644
--- a/mojo/public/cpp/bindings/array.h
+++ b/mojo/public/cpp/bindings/array.h
@@ -16,6 +16,7 @@
#include "base/macros.h"
#include "mojo/public/cpp/bindings/lib/array_internal.h"
#include "mojo/public/cpp/bindings/lib/bindings_internal.h"
+#include "mojo/public/cpp/bindings/lib/clone_equals_util.h"
#include "mojo/public/cpp/bindings/lib/template_util.h"
#include "mojo/public/cpp/bindings/type_converter.h"
@@ -137,14 +138,13 @@ class Array {
const std::vector<T>& storage() const { return vec_; }
// Passes the underlying storage and resets this array to null.
- //
- // TODO(yzshen): Consider changing this to a rvalue-ref-qualified conversion
- // to std::vector<T> after we move to MSVC 2015.
std::vector<T> PassStorage() {
is_null_ = true;
return std::move(vec_);
}
+ operator const std::vector<T>&() const { return vec_; }
+
void Swap(Array* other) {
std::swap(is_null_, other->is_null_);
vec_.swap(other->vec_);
@@ -169,10 +169,8 @@ class Array {
Array Clone() const {
Array result;
result.is_null_ = is_null_;
- result.vec_.reserve(vec_.size());
- for (const auto& element : vec_)
- result.vec_.push_back(internal::Clone(element));
- return std::move(result);
+ result.vec_ = internal::Clone(vec_);
+ return result;
}
// Indicates whether the contents of this array are equal to |other|. A null
@@ -181,13 +179,7 @@ class Array {
bool Equals(const Array& other) const {
if (is_null() != other.is_null())
return false;
- if (size() != other.size())
- return false;
- for (size_t i = 0; i < size(); ++i) {
- if (!internal::Equals(at(i), other.at(i)))
- return false;
- }
- return true;
+ return internal::Equals(vec_, other.vec_);
}
private:
« no previous file with comments | « mojo/public/cpp/bindings/BUILD.gn ('k') | mojo/public/cpp/bindings/array_traits_stl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698