! * \brief Constructs a container and copy from another * \param cap The capacity of the container * \param from Source of the copy * \return Ref-counted ArrayObj requested */
| 52 | * \return Ref-counted ArrayObj requested |
| 53 | */ |
| 54 | static ObjectPtr<ArrayObj> CopyFrom(int64_t cap, ArrayObj* from) { |
| 55 | int64_t size = from->TVMFFISeqCell::size; |
| 56 | if (size > cap) { |
| 57 | TVM_FFI_THROW(ValueError) << "Not enough capacity"; |
| 58 | } |
| 59 | ObjectPtr<ArrayObj> p = ArrayObj::Empty(cap); |
| 60 | Any* write = p->MutableBegin(); |
| 61 | Any* read = from->MutableBegin(); |
| 62 | // To ensure exception safety, size is only incremented after the initialization succeeds |
| 63 | for (int64_t& i = p->TVMFFISeqCell::size = 0; i < size; ++i) { |
| 64 | new (write++) Any(*read++); |
| 65 | } |
| 66 | return p; |
| 67 | } |
| 68 | |
| 69 | /*! |
| 70 | * \brief Constructs a container and move from another |
nothing calls this directly
no test coverage detected