From 83dc7f08552ed9daca27fdc684f4ec0d47ef77d3 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Sat, 24 Aug 2013 01:29:03 -0700 Subject: [PATCH] Fix performance problems in AString. --- public/amtl/am-string.h | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/public/amtl/am-string.h b/public/amtl/am-string.h index d91e2542..76611f1a 100644 --- a/public/amtl/am-string.h +++ b/public/amtl/am-string.h @@ -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;