Fix performance problems in AString.
Fix performance problems in AString.
1.1 --- a/public/amtl/am-string.h Fri Aug 23 22:29:44 2013 -0700
1.2 +++ b/public/amtl/am-string.h Sat Aug 24 01:29:03 2013 -0700
1.3 @@ -51,18 +51,32 @@
1.4 set(str, length);
1.5 }
1.6 AString(const AString &other) {
1.7 - set(other.chars_, other.length_);
1.8 + if (other.length_)
1.9 + set(other.chars_, other.length_);
1.10 }
1.11
1.12 AString &operator =(const char *str) {
1.13 - set(str, strlen(str));
1.14 + if (str && str[0]) {
1.15 + set(str, strlen(str));
1.16 + } else {
1.17 + chars_ = NULL;
1.18 + length_ = 0;
1.19 + }
1.20 return *this;
1.21 }
1.22 AString &operator =(const AString &other) {
1.23 - set(other.chars_, other.length_);
1.24 + if (other.length_) {
1.25 + set(other.chars_, other.length_);
1.26 + } else {
1.27 + chars_ = NULL;
1.28 + length_ = 0;
1.29 + }
1.30 return *this;
1.31 }
1.32
1.33 + int compare(const AString &other) const {
1.34 + return strcmp(chars(), other.chars());
1.35 + }
1.36 bool operator ==(const AString &other) const {
1.37 return other.length() == length() &&
1.38 memcmp(other.chars(), chars(), length()) == 0;