This is an automated email from the ASF dual-hosted git repository. tqchen pushed a commit to branch refactor-s2 in repository https://gitbox.apache.org/repos/asf/tvm.git
commit 4f3df502df61794d672c509208a0c04a25ebc8fc Author: tqchen <[email protected]> AuthorDate: Tue Apr 22 10:15:18 2025 -0400 [FFI] Make the data/size fields of ByteObjBase inline --- ffi/include/tvm/ffi/any.h | 6 +++--- ffi/include/tvm/ffi/string.h | 27 ++++++++++++--------------- 2 files changed, 15 insertions(+), 18 deletions(-) diff --git a/ffi/include/tvm/ffi/any.h b/ffi/include/tvm/ffi/any.h index ccac4980ea..518342b3ea 100644 --- a/ffi/include/tvm/ffi/any.h +++ b/ffi/include/tvm/ffi/any.h @@ -441,7 +441,7 @@ struct AnyHash { src.data_.type_index == TypeIndex::kTVMFFIBytes) { const BytesObjBase* src_str = details::AnyUnsafe::CopyFromAnyStorageAfterCheck<const BytesObjBase*>(src); - return details::StableHashBytes(src_str->bytes.data, src_str->bytes.size); + return details::StableHashBytes(src_str->data, src_str->size); } else { return src.data_.v_uint64; } @@ -469,8 +469,8 @@ struct AnyEqual { details::AnyUnsafe::CopyFromAnyStorageAfterCheck<const BytesObjBase*>(lhs); const BytesObjBase* rhs_str = details::AnyUnsafe::CopyFromAnyStorageAfterCheck<const BytesObjBase*>(rhs); - return Bytes::memncmp(lhs_str->bytes.data, rhs_str->bytes.data, lhs_str->bytes.size, - rhs_str->bytes.size) == 0; + return Bytes::memncmp(lhs_str->data, rhs_str->data, lhs_str->size, + rhs_str->size) == 0; } return false; } diff --git a/ffi/include/tvm/ffi/string.h b/ffi/include/tvm/ffi/string.h index 70a3053511..da9142a292 100644 --- a/ffi/include/tvm/ffi/string.h +++ b/ffi/include/tvm/ffi/string.h @@ -48,10 +48,7 @@ namespace tvm { namespace ffi { /*! \brief Base class for bytes and string. */ -class BytesObjBase : public Object { - public: - /*! \brief The internal byte array.*/ - TVMFFIByteArray bytes; +class BytesObjBase : public Object, public TVMFFIByteArray { }; /*! @@ -84,8 +81,8 @@ template <typename Base> class BytesObjStdImpl : public Base { public: explicit BytesObjStdImpl(std::string other) : data_{other} { - this->bytes.data = data_.data(); - this->bytes.size = data_.size(); + this->data = data_.data(); + this->size = data_.size(); } private: @@ -99,8 +96,8 @@ TVM_FFI_INLINE ObjectPtr<Base> MakeInplaceBytes(const char* data, size_t length) static_assert(alignof(Base) % alignof(char) == 0); static_assert(sizeof(Base) % alignof(char) == 0); char* dest_data = reinterpret_cast<char*>(p.get()) + sizeof(Base); - p->bytes.data = dest_data; - p->bytes.size = length; + p->data = dest_data; + p->size = length; std::memcpy(dest_data, data, length); dest_data[length] = '\0'; return p; @@ -152,19 +149,19 @@ class Bytes : public ObjectRef { * * \return size_t string length */ - size_t size() const { return get()->bytes.size; } + size_t size() const { return get()->size; } /*! * \brief Return the data pointer * * \return const char* data pointer */ - const char* data() const { return get()->bytes.data; } + const char* data() const { return get()->data; } /*! * \brief Convert String to an std::string object * * \return std::string */ - operator std::string() const { return std::string{get()->bytes.data, size()}; } + operator std::string() const { return std::string{get()->data, size()}; } TVM_FFI_DEFINE_NOTNULLABLE_OBJECT_REF_METHODS(Bytes, ObjectRef, BytesObj); @@ -306,7 +303,7 @@ class String : public ObjectRef { * * \return const char* */ - const char* c_str() const { return get()->bytes.data; } + const char* c_str() const { return get()->data; } /*! * \brief Return the length of the string @@ -315,7 +312,7 @@ class String : public ObjectRef { */ size_t size() const { const auto* ptr = get(); - return ptr->bytes.size; + return ptr->size; } /*! @@ -351,14 +348,14 @@ class String : public ObjectRef { * * \return const char* data pointer */ - const char* data() const { return get()->bytes.data; } + const char* data() const { return get()->data; } /*! * \brief Convert String to an std::string object * * \return std::string */ - operator std::string() const { return std::string{get()->bytes.data, size()}; } + operator std::string() const { return std::string{get()->data, size()}; } TVM_FFI_DEFINE_NOTNULLABLE_OBJECT_REF_METHODS(String, ObjectRef, StringObj);
