diff options
author | Ian Lance Taylor <iant@google.com> | 2007-12-14 05:24:17 +0000 |
---|---|---|
committer | Ian Lance Taylor <iant@google.com> | 2007-12-14 05:24:17 +0000 |
commit | 6d01333390a0047a4e8ec0d69f4d1c8f43c3fc55 (patch) | |
tree | aa539a8dc67b986680175065607f9f51c471b831 /gold/stringpool.cc | |
parent | 460c00b558bc0cf4501c514b0ff13c7d48750165 (diff) | |
download | gdb-6d01333390a0047a4e8ec0d69f4d1c8f43c3fc55.zip gdb-6d01333390a0047a4e8ec0d69f4d1c8f43c3fc55.tar.gz gdb-6d01333390a0047a4e8ec0d69f4d1c8f43c3fc55.tar.bz2 |
From Craig Silverstein: size hash tables to avoid resizing.
Diffstat (limited to 'gold/stringpool.cc')
-rw-r--r-- | gold/stringpool.cc | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/gold/stringpool.cc b/gold/stringpool.cc index 0ac1dcb..7bf8365 100644 --- a/gold/stringpool.cc +++ b/gold/stringpool.cc @@ -58,6 +58,30 @@ Stringpool_template<Stringpool_char>::~Stringpool_template() this->clear(); } +// Resize the internal hashtable with the expectation we'll get n new +// elements. Note that the hashtable constructor takes a "number of +// buckets you'd like," rather than "number of elements you'd like," +// but that's the best we can do. + +template<typename Stringpool_char> +void +Stringpool_template<Stringpool_char>::reserve(unsigned int n) +{ +#if defined(HAVE_TR1_UNORDERED_MAP) + // rehash() implementation is broken in gcc 4.0.3's stl + //this->string_set_.rehash(this->string_set_.size() + n); + //return; +#elif defined(HAVE_EXT_HASH_MAP) + this->string_set_.resize(this->string_set_.size() + n); + return; +#endif + + // This is the generic "reserve" code, if no #ifdef above triggers. + String_set_type new_string_set(this->string_set_.size() + n); + new_string_set.insert(this->string_set_.begin(), this->string_set_.end()); + this->string_set_.swap(new_string_set); +} + // Return the length of a string of arbitrary character type. template<typename Stringpool_char> @@ -212,7 +236,11 @@ Stringpool_template<Stringpool_char>::add_string(const Stringpool_char* s, ++this->next_index_; if (pkey != NULL) - *pkey = psd->index * key_mult; + { + *pkey = psd->index * key_mult; + // Ensure there was no overflow. + gold_assert(*pkey / key_mult == psd->index); + } if (front) this->strings_.push_front(psd); |