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

Method InitSpaceForSize

include/tvm/ffi/string.h:207–228  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

205 */
206 template <typename LargeObj>
207 char* InitSpaceForSize(size_t size, int32_t small_type_index, int32_t large_type_index) {
208 size_t kMaxSmallBytesLen = sizeof(int64_t) - 1;
209 // first zero the content, this is important for exception safety
210 data_.type_index = small_type_index;
211 data_.zero_padding = 0;
212 if (size <= kMaxSmallBytesLen) {
213 // set up the size accordingly
214 data_.small_str_len = static_cast<uint32_t>(size);
215 return data_.v_bytes;
216 } else {
217 // allocate from heap
218 ObjectPtr<LargeObj> ptr = make_inplace_array_object<LargeObj, char>(size + 1);
219 char* dest_data = reinterpret_cast<char*>(ptr.get()) + sizeof(LargeObj);
220 ptr->data = dest_data;
221 ptr->size = size;
222 TVM_FFI_CLEAR_PTR_PADDING_IN_FFI_ANY(&data_);
223 data_.v_obj = details::ObjectUnsafe::MoveObjectPtrToTVMFFIObjectPtr(std::move(ptr));
224 // now reset the type index to str
225 data_.type_index = large_type_index;
226 return dest_data;
227 }
228 }
229
230 void InitTypeIndex(int32_t type_index) { data_.type_index = type_index; }
231

Callers

nothing calls this directly

Calls 1

getMethod · 0.45

Tested by

no test coverage detected