| OLD | NEW |
| 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 MOJO_PUBLIC_CPP_BINDINGS_LIB_ARRAY_INTERNAL_H_ | 5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_LIB_ARRAY_INTERNAL_H_ |
| 6 #define MOJO_PUBLIC_CPP_BINDINGS_LIB_ARRAY_INTERNAL_H_ | 6 #define MOJO_PUBLIC_CPP_BINDINGS_LIB_ARRAY_INTERNAL_H_ |
| 7 | 7 |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 #include <stdint.h> | 9 #include <stdint.h> |
| 10 | |
| 11 #include <new> | 10 #include <new> |
| 11 #include <utility> |
| 12 #include <vector> | 12 #include <vector> |
| 13 | 13 |
| 14 #include "mojo/public/c/system/macros.h" | 14 #include "mojo/public/c/system/macros.h" |
| 15 #include "mojo/public/cpp/bindings/lib/bindings_internal.h" | 15 #include "mojo/public/cpp/bindings/lib/bindings_internal.h" |
| 16 #include "mojo/public/cpp/bindings/lib/bindings_serialization.h" | 16 #include "mojo/public/cpp/bindings/lib/bindings_serialization.h" |
| 17 #include "mojo/public/cpp/bindings/lib/bounds_checker.h" | 17 #include "mojo/public/cpp/bindings/lib/bounds_checker.h" |
| 18 #include "mojo/public/cpp/bindings/lib/buffer.h" | 18 #include "mojo/public/cpp/bindings/lib/buffer.h" |
| 19 #include "mojo/public/cpp/bindings/lib/map_data_internal.h" | 19 #include "mojo/public/cpp/bindings/lib/map_data_internal.h" |
| 20 #include "mojo/public/cpp/bindings/lib/template_util.h" | 20 #include "mojo/public/cpp/bindings/lib/template_util.h" |
| 21 #include "mojo/public/cpp/bindings/lib/validate_params.h" | 21 #include "mojo/public/cpp/bindings/lib/validate_params.h" |
| (...skipping 476 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 498 size_t old_size = vec->size(); | 498 size_t old_size = vec->size(); |
| 499 for (size_t i = size; i < old_size; i++) | 499 for (size_t i = size; i < old_size; i++) |
| 500 reinterpret_cast<T*>(vec->at(i).buf)->~T(); | 500 reinterpret_cast<T*>(vec->at(i).buf)->~T(); |
| 501 ResizeStorage(vec, size); | 501 ResizeStorage(vec, size); |
| 502 for (size_t i = old_size; i < vec->size(); i++) | 502 for (size_t i = old_size; i < vec->size(); i++) |
| 503 new (vec->at(i).buf) T(); | 503 new (vec->at(i).buf) T(); |
| 504 } | 504 } |
| 505 static inline void PushBack(std::vector<StorageType>* vec, RefType value) { | 505 static inline void PushBack(std::vector<StorageType>* vec, RefType value) { |
| 506 size_t old_size = vec->size(); | 506 size_t old_size = vec->size(); |
| 507 ResizeStorage(vec, old_size + 1); | 507 ResizeStorage(vec, old_size + 1); |
| 508 new (vec->at(old_size).buf) T(value.Pass()); | 508 new (vec->at(old_size).buf) T(std::move(value)); |
| 509 } | 509 } |
| 510 static inline void ResizeStorage(std::vector<StorageType>* vec, size_t size) { | 510 static inline void ResizeStorage(std::vector<StorageType>* vec, size_t size) { |
| 511 if (size <= vec->capacity()) { | 511 if (size <= vec->capacity()) { |
| 512 vec->resize(size); | 512 vec->resize(size); |
| 513 return; | 513 return; |
| 514 } | 514 } |
| 515 std::vector<StorageType> new_storage(size); | 515 std::vector<StorageType> new_storage(size); |
| 516 for (size_t i = 0; i < vec->size(); i++) | 516 for (size_t i = 0; i < vec->size(); i++) |
| 517 new (new_storage.at(i).buf) T(at(vec, i).Pass()); | 517 new (new_storage.at(i).buf) T(std::move(at(vec, i))); |
| 518 vec->swap(new_storage); | 518 vec->swap(new_storage); |
| 519 Finalize(&new_storage); | 519 Finalize(&new_storage); |
| 520 } | 520 } |
| 521 static inline void Clone(const std::vector<StorageType>& src_vec, | 521 static inline void Clone(const std::vector<StorageType>& src_vec, |
| 522 std::vector<StorageType>* dest_vec) { | 522 std::vector<StorageType>* dest_vec) { |
| 523 Resize(dest_vec, src_vec.size()); | 523 Resize(dest_vec, src_vec.size()); |
| 524 for (size_t i = 0; i < src_vec.size(); ++i) | 524 for (size_t i = 0; i < src_vec.size(); ++i) |
| 525 at(dest_vec, i) = at(&src_vec, i).Clone(); | 525 at(dest_vec, i) = at(&src_vec, i).Clone(); |
| 526 } | 526 } |
| 527 }; | 527 }; |
| 528 | 528 |
| 529 template <> | 529 template <> |
| 530 struct WrapperTraits<String, false> { | 530 struct WrapperTraits<String, false> { |
| 531 typedef String_Data* DataType; | 531 typedef String_Data* DataType; |
| 532 }; | 532 }; |
| 533 | 533 |
| 534 } // namespace internal | 534 } // namespace internal |
| 535 } // namespace mojo | 535 } // namespace mojo |
| 536 | 536 |
| 537 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_ARRAY_INTERNAL_H_ | 537 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_ARRAY_INTERNAL_H_ |
| OLD | NEW |