mirror of
https://github.com/open-source-parsers/jsoncpp.git
synced 2024-12-26 18:51:04 +08:00
stop computing strlen() in CZString
This commit is contained in:
parent
8a77037320
commit
e6b46e4503
@ -197,8 +197,8 @@ bool Value::CZString::operator<(const CZString& other) const {
|
||||
if (!cstr_) return index_ < other.index_;
|
||||
//return strcmp(cstr_, other.cstr_) < 0;
|
||||
// Assume both are strings.
|
||||
unsigned this_len = strlen(this->cstr_);
|
||||
unsigned other_len = strlen(other.cstr_);
|
||||
unsigned this_len = this->storage_.length_;
|
||||
unsigned other_len = other.storage_.length_;
|
||||
unsigned min_len = std::min(this_len, other_len);
|
||||
int comp = memcmp(this->cstr_, other.cstr_, min_len);
|
||||
if (comp < 0) return true;
|
||||
@ -210,8 +210,8 @@ bool Value::CZString::operator==(const CZString& other) const {
|
||||
if (!cstr_) return index_ == other.index_;
|
||||
//return strcmp(cstr_, other.cstr_) == 0;
|
||||
// Assume both are strings.
|
||||
unsigned this_len = strlen(this->cstr_);
|
||||
unsigned other_len = strlen(other.cstr_);
|
||||
unsigned this_len = this->storage_.length_;
|
||||
unsigned other_len = other.storage_.length_;
|
||||
if (this_len != other_len) return false;
|
||||
int comp = memcmp(this->cstr_, other.cstr_, this_len);
|
||||
return comp == 0;
|
||||
|
Loading…
x
Reference in New Issue
Block a user