Skip to content

Commit

Permalink
[Runtime][Object] Add Object::unique() (apache#7615)
Browse files Browse the repository at this point in the history
  • Loading branch information
junrushao authored and trevor-m committed May 11, 2021
1 parent e6e262d commit 0dbd9ba
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion include/tvm/runtime/object.h
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,11 @@ class TVM_DLL Object {
*/
template <typename TargetType>
inline bool IsInstance() const;

/*!
* \return Weather the cell has only one reference
* \note We use stl style naming to be consistent with known API in shared_ptr.
*/
inline bool unique() const;
/*!
* \brief Get the type key of the corresponding index from runtime.
* \param tindex The type index.
Expand Down Expand Up @@ -831,6 +835,8 @@ inline bool Object::IsInstance() const {
}
}

inline bool Object::unique() const { return use_count() == 1; }

template <typename ObjectType>
inline const ObjectType* ObjectRef::as() const {
if (data_ != nullptr && data_->IsInstance<ObjectType>()) {
Expand Down

0 comments on commit 0dbd9ba

Please sign in to comment.