# HG changeset patch # User David Anderson # Date 1377332943 25200 # Node ID c405c08e0f5e110a0c904c41f2113abe52854cc6 # Parent 56a4c27831fee7d20495e67ba19fd96c07d5aaf4 Fix performance problems in AString. diff -r 56a4c27831fe -r c405c08e0f5e public/amtl/am-string.h --- a/public/amtl/am-string.h Fri Aug 23 22:29:44 2013 -0700 +++ b/public/amtl/am-string.h Sat Aug 24 01:29:03 2013 -0700 @@ -51,18 +51,32 @@ 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;