Various performance and build fixes.
Various performance and build fixes.
1.1 --- a/include/am-hashmap.h Fri Aug 23 22:37:59 2013 -0700
1.2 +++ b/include/am-hashmap.h Sat Aug 24 01:31:41 2013 -0700
1.3 @@ -57,6 +57,10 @@
1.4 K key;
1.5 V value;
1.6
1.7 + Entry()
1.8 + {
1.9 + }
1.10 +
1.11 Entry(const K &aKey, const V &aValue)
1.12 : key(aKey),
1.13 value(aValue)
1.14 @@ -120,6 +124,13 @@
1.15 return table_.add(i, Entry(key, value));
1.16 }
1.17
1.18 + // This can be used to avoid compiler constructed temporaries, since AMTL
1.19 + // does not yet support move semantics. If you use this, the key and value
1.20 + // must be set after.
1.21 + bool add(Insert &i) {
1.22 + return table_.add(i);
1.23 + }
1.24 +
1.25 size_t estimateMemoryUse() const {
1.26 return table_.estimateMemoryUse();
1.27 }
2.1 --- a/include/am-hashtable.h Fri Aug 23 22:37:59 2013 -0700
2.2 +++ b/include/am-hashtable.h Sat Aug 24 01:31:41 2013 -0700
2.3 @@ -353,7 +353,7 @@
2.4 }
2.5
2.6 public:
2.7 - HashTable(AllocPolicy ap)
2.8 + HashTable(AllocPolicy ap = AllocPolicy())
2.9 : AllocPolicy(ap),
2.10 capacity_(0),
2.11 nelements_(0),
2.12 @@ -420,6 +420,9 @@
2.13 bool add(Insert &i, const Payload &payload) {
2.14 return internalAdd(i, payload);
2.15 }
2.16 + bool add(Insert &i) {
2.17 + return internalAdd(i, Payload());
2.18 + }
2.19
2.20 bool checkDensity() {
2.21 if (underloaded())
3.1 --- a/include/am-string.h Fri Aug 23 22:37:59 2013 -0700
3.2 +++ b/include/am-string.h Sat Aug 24 01:31:41 2013 -0700
3.3 @@ -51,18 +51,32 @@
3.4 set(str, length);
3.5 }
3.6 AString(const AString &other) {
3.7 - set(other.chars_, other.length_);
3.8 + if (other.length_)
3.9 + set(other.chars_, other.length_);
3.10 }
3.11
3.12 AString &operator =(const char *str) {
3.13 - set(str, strlen(str));
3.14 + if (str && str[0]) {
3.15 + set(str, strlen(str));
3.16 + } else {
3.17 + chars_ = NULL;
3.18 + length_ = 0;
3.19 + }
3.20 return *this;
3.21 }
3.22 AString &operator =(const AString &other) {
3.23 - set(other.chars_, other.length_);
3.24 + if (other.length_) {
3.25 + set(other.chars_, other.length_);
3.26 + } else {
3.27 + chars_ = NULL;
3.28 + length_ = 0;
3.29 + }
3.30 return *this;
3.31 }
3.32
3.33 + int compare(const AString &other) const {
3.34 + return strcmp(chars(), other.chars());
3.35 + }
3.36 bool operator ==(const AString &other) const {
3.37 return other.length() == length() &&
3.38 memcmp(other.chars(), chars(), length()) == 0;