susumu.yata
null+****@clear*****
Fri Sep 26 16:24:53 JST 2014
susumu.yata 2014-09-26 16:24:53 +0900 (Fri, 26 Sep 2014) New Revision: f02f031d52a2bdda3c5db0f34353428086c7b5bd https://github.com/groonga/grnxx/commit/f02f031d52a2bdda3c5db0f34353428086c7b5bd Message: Update Name to use String. (#75) Modified files: lib/grnxx/name.cpp lib/grnxx/name.hpp Modified: lib/grnxx/name.cpp (+1 -13) =================================================================== --- lib/grnxx/name.cpp 2014-09-26 16:12:26 +0900 (cddf6ca) +++ lib/grnxx/name.cpp 2014-09-26 16:24:53 +0900 (dd3f9f1) @@ -21,19 +21,7 @@ bool Name::assign(Error *error, const StringCRef &name) { if (!test(error, name)) { return false; } - - unique_ptr<char[]> new_data(new (std::nothrow) char[name.size() + 1]); - if (!new_data) { - GRNXX_ERROR_SET(error, NO_MEMORY, - "Memory allocation failed: size = %" PRIi64, name.size()); - return false; - } - std::memcpy(new_data.get(), name.data(), name.size()); - new_data[name.size()] = '\0'; - - data_ = std::move(new_data); - size_ = name.size(); - return true; + return string_.assign(error, name); } bool Name::test(Error *error, const StringCRef &name) { Modified: lib/grnxx/name.hpp (+6 -10) =================================================================== --- lib/grnxx/name.hpp 2014-09-26 16:12:26 +0900 (b1033e5) +++ lib/grnxx/name.hpp 2014-09-26 16:24:53 +0900 (fde9686) @@ -7,25 +7,22 @@ namespace grnxx { class Name { public: - Name() : data_(nullptr), size_(0) {} - - Name(const Name &) = delete; - Name &operator=(const Name &) = delete; + Name() : string_() {} const char &operator[](Int i) const { - return data_[i]; + return string_[i]; } const char *data() const { - return data_.get(); + return string_.data(); } Int size() const { - return size_; + return string_.size(); } // Return a reference to the name string. StringCRef ref() const { - return StringCRef(data_.get(), size_); + return string_.ref(); } // Assign a new name. @@ -41,8 +38,7 @@ class Name { bool assign(Error *error, const StringCRef &name); private: - unique_ptr<char[]> data_; - Int size_; + String string_; static constexpr Int MIN_SIZE = 1; static constexpr Int MAX_SIZE = 1023; -------------- next part -------------- HTML����������������������������...Download