Skip to content

Commit

Permalink
use FromStd
Browse files Browse the repository at this point in the history
  • Loading branch information
zhiics committed Jun 15, 2020
1 parent 7dfdce7 commit 08029f5
Showing 1 changed file with 2 additions and 29 deletions.
31 changes: 2 additions & 29 deletions include/tvm/runtime/container.h
Original file line number Diff line number Diff line change
Expand Up @@ -1106,8 +1106,6 @@ class StringObj : public Object {
private:
/*! \brief String object which is moved from std::string container. */
class FromStd;
/*! \brief String object that is constructed from char*. */
class FromCharPtr;

friend class String;
};
Expand Down Expand Up @@ -1159,7 +1157,8 @@ class String : public ObjectRef {
*
* \param other a char array.
*/
String(const char* other); // NOLINT(*);
String(const char* other) // NOLINT(*)
: String(std::string(other)) {}

/*!
* \brief Change the value the reference object points to.
Expand Down Expand Up @@ -1355,39 +1354,13 @@ class StringObj::FromStd : public StringObj {
friend class String;
};

/*!
* \brief The class that initializes and manages the memory of a String object
* created from char pointers.
*/
class StringObj::FromCharPtr : public StringObj, InplaceArrayBase<StringObj::FromCharPtr, char> {
public:
/*! \brief The size function needed by InplaceArrayBase */
size_t GetSize() const { return size_; }

private:
/*! \brief The length of the chars. */
size_t size_;

friend class String;
friend class InplaceArrayBase<StringObj::FromCharPtr, char>;
};

inline String::String(std::string other) {
auto ptr = make_object<StringObj::FromStd>(std::move(other));
ptr->size = ptr->data_container.size();
ptr->data = ptr->data_container.data();
data_ = std::move(ptr);
}

inline String::String(const char* other) {
size_t size = std::strlen(other);
auto ptr = make_inplace_array_object<StringObj::FromCharPtr, char>(size);
ptr->size_ = size;
ptr->size = size;
ptr->data = other;
data_ = std::move(ptr);
}

inline String& String::operator=(std::string other) {
String replace{std::move(other)};
data_.swap(replace.data_);
Expand Down

0 comments on commit 08029f5

Please sign in to comment.