| Index: mojo/public/cpp/bindings/lib/array_internal.h
|
| diff --git a/mojo/public/cpp/bindings/lib/array_internal.h b/mojo/public/cpp/bindings/lib/array_internal.h
|
| index 99991c5c862b3035168496acc28d1c24a522e91e..b0a8908e77d19c7ee10883cd7c25dd7e993a58cf 100644
|
| --- a/mojo/public/cpp/bindings/lib/array_internal.h
|
| +++ b/mojo/public/cpp/bindings/lib/array_internal.h
|
| @@ -290,6 +290,7 @@ template <typename T> struct ArrayTraits<T, false> {
|
| typedef T StorageType;
|
| typedef typename std::vector<T>::reference RefType;
|
| typedef typename std::vector<T>::const_reference ConstRefType;
|
| + typedef ConstRefType ForwardType;
|
| static inline void Initialize(std::vector<T>* vec) {
|
| }
|
| static inline void Finalize(std::vector<T>* vec) {
|
| @@ -300,6 +301,12 @@ template <typename T> struct ArrayTraits<T, false> {
|
| static inline RefType at(std::vector<T>* vec, size_t offset) {
|
| return vec->at(offset);
|
| }
|
| + static inline void Resize(std::vector<T>* vec, size_t size) {
|
| + vec->resize(size);
|
| + }
|
| + static inline void PushBack(std::vector<T>* vec, ForwardType value) {
|
| + vec->push_back(value);
|
| + }
|
| };
|
|
|
| template <typename T> struct ArrayTraits<T, true> {
|
| @@ -308,6 +315,7 @@ template <typename T> struct ArrayTraits<T, true> {
|
| };
|
| typedef T& RefType;
|
| typedef const T& ConstRefType;
|
| + typedef T ForwardType;
|
| static inline void Initialize(std::vector<StorageType>* vec) {
|
| for (size_t i = 0; i < vec->size(); ++i)
|
| new (vec->at(i).buf) T();
|
| @@ -323,6 +331,30 @@ template <typename T> struct ArrayTraits<T, true> {
|
| static inline RefType at(std::vector<StorageType>* vec, size_t offset) {
|
| return *reinterpret_cast<T*>(vec->at(offset).buf);
|
| }
|
| + static inline void Resize(std::vector<StorageType>* vec, size_t size) {
|
| + size_t old_size = vec->size();
|
| + for (size_t i = size; i < old_size; i++)
|
| + reinterpret_cast<T*>(vec->at(i).buf)->~T();
|
| + ResizeStorage(vec, size);
|
| + for (size_t i = old_size; i < vec->size(); i++)
|
| + new (vec->at(i).buf) T();
|
| + }
|
| + static inline void PushBack(std::vector<StorageType>* vec, RefType value) {
|
| + size_t old_size = vec->size();
|
| + ResizeStorage(vec, old_size + 1);
|
| + new (vec->at(old_size).buf) T(value.Pass());
|
| + }
|
| + static inline void ResizeStorage(std::vector<StorageType>* vec, size_t size) {
|
| + if (size <= vec->capacity()) {
|
| + vec->resize(size);
|
| + return;
|
| + }
|
| + std::vector<StorageType> new_storage(size);
|
| + for (size_t i = 0; i < vec->size(); i++)
|
| + new (new_storage.at(i).buf) T(at(vec, i).Pass());
|
| + vec->swap(new_storage);
|
| + Finalize(&new_storage);
|
| + }
|
| };
|
|
|
| template <> struct WrapperTraits<String, false> {
|
|
|