| 630 | */ |
| 631 | template <typename IterType> |
| 632 | void Assign(IterType first, IterType last) { // NOLINT(performance-unnecessary-value-param) |
| 633 | int64_t cap = std::distance(first, last); |
| 634 | if (cap < 0) { |
| 635 | TVM_FFI_THROW(ValueError) << "cannot construct an Array of negative size"; |
| 636 | } |
| 637 | ArrayObj* p = GetArrayObj(); |
| 638 | if (p != nullptr && data_.unique() && p->TVMFFISeqCell::capacity >= cap) { |
| 639 | // do not have to make new space |
| 640 | p->clear(); |
| 641 | } else { |
| 642 | // create new space |
| 643 | data_ = ArrayObj::Empty(cap); |
| 644 | p = GetArrayObj(); |
| 645 | } |
| 646 | // To ensure exception safety, size is only incremented after the initialization succeeds |
| 647 | Any* itr = p->MutableBegin(); |
| 648 | for (int64_t& i = p->TVMFFISeqCell::size = 0; i < cap; ++i, ++first, ++itr) { |
| 649 | new (itr) Any(*first); |
| 650 | } |
| 651 | } |
| 652 | |
| 653 | /*! |
| 654 | * \brief Copy on write semantics |
nothing calls this directly
no test coverage detected