diff --git a/src/paramdict.cpp b/src/paramdict.cpp index a6a7c893c2e..4704ea169e6 100644 --- a/src/paramdict.cpp +++ b/src/paramdict.cpp @@ -372,14 +372,6 @@ int ParamDict::load_param(const DataReader& dr) d->params[id].s = std::string(vstr); } -#if NCNN_SIMPLESTL - // simple stl string has no tail zero by default, append one - int len = d->params[id].s.size(); - d->params[id].s.resize(len + 1); - d->params[id].s[len] = '\0'; - d->params[id].s.resize(len); -#endif - d->params[id].type = 7; continue; @@ -565,13 +557,6 @@ int ParamDict::load_param_bin(const DataReader& dr) d->params[id].s = tmpstr.data(); -#if NCNN_SIMPLESTL - // simple stl string has no tail zero by default, append one - d->params[id].s.resize(len + 1); - d->params[id].s[len] = '\0'; - d->params[id].s.resize(len); -#endif - d->params[id].type = 7; } else if (is_array) diff --git a/src/simplestl.h b/src/simplestl.h index 00ff4680186..992bf9bcc4a 100644 --- a/src/simplestl.h +++ b/src/simplestl.h @@ -536,15 +536,11 @@ struct NCNN_EXPORT string : public vector } bool operator==(const string& str2) const { - return strcmp(data_, str2.data_) == 0; + return size_ == str2.size_ && strncmp(data_, str2.data_, size_) == 0; } - bool operator==(const char* str2) const + bool operator!=(const string& str2) const { - return strcmp(data_, str2) == 0; - } - bool operator!=(const char* str2) const - { - return strcmp(data_, str2) != 0; + return size_ != str2.size_ || strncmp(data_, str2.data_, size_) != 0; } string& operator+=(const string& str1) {