MCPcopy Create free account
hub / github.com/apache/tvm-ffi / MoveFrom

Method MoveFrom

include/tvm/ffi/container/array.h:75–89  ·  view source on GitHub ↗

! * \brief Constructs a container and move from another * \param cap The capacity of the container * \param from Source of the move * \return Ref-counted ArrayObj requested */

Source from the content-addressed store, hash-verified

73 * \return Ref-counted ArrayObj requested
74 */
75 static ObjectPtr<ArrayObj> MoveFrom(int64_t cap, ArrayObj* from) {
76 int64_t size = from->TVMFFISeqCell::size;
77 if (size > cap) {
78 TVM_FFI_THROW(RuntimeError) << "Not enough capacity";
79 }
80 ObjectPtr<ArrayObj> p = ArrayObj::Empty(cap);
81 Any* write = p->MutableBegin();
82 Any* read = from->MutableBegin();
83 // To ensure exception safety, size is only incremented after the initialization succeeds
84 for (int64_t& i = p->TVMFFISeqCell::size = 0; i < size; ++i) {
85 new (write++) Any(std::move(*read++));
86 }
87 from->TVMFFISeqCell::size = 0;
88 return p;
89 }
90
91 /*!
92 * \brief Constructs a container with n elements. Each element is a copy of val

Callers

nothing calls this directly

Calls 2

MutableBeginMethod · 0.80
EmptyFunction · 0.50

Tested by

no test coverage detected