Fix performance problems in AString.

This commit is contained in:
David Anderson 2013-08-24 01:29:03 -07:00
parent 90a2d1bb39
commit 83dc7f0855

View File

@ -51,18 +51,32 @@ class AString
set(str, length);
}
AString(const AString &other) {
set(other.chars_, other.length_);
if (other.length_)
set(other.chars_, other.length_);
}
AString &operator =(const char *str) {
set(str, strlen(str));
if (str && str[0]) {
set(str, strlen(str));
} else {
chars_ = NULL;
length_ = 0;
}
return *this;
}
AString &operator =(const AString &other) {
set(other.chars_, other.length_);
if (other.length_) {
set(other.chars_, other.length_);
} else {
chars_ = NULL;
length_ = 0;
}
return *this;
}
int compare(const AString &other) const {
return strcmp(chars(), other.chars());
}
bool operator ==(const AString &other) const {
return other.length() == length() &&
memcmp(other.chars(), chars(), length()) == 0;