aboutsummaryrefslogtreecommitdiff
path: root/gold/layout.cc
diff options
context:
space:
mode:
authorIan Lance Taylor <iant@google.com>2007-12-14 05:24:17 +0000
committerIan Lance Taylor <iant@google.com>2007-12-14 05:24:17 +0000
commit6d01333390a0047a4e8ec0d69f4d1c8f43c3fc55 (patch)
treeaa539a8dc67b986680175065607f9f51c471b831 /gold/layout.cc
parent460c00b558bc0cf4501c514b0ff13c7d48750165 (diff)
downloadgdb-6d01333390a0047a4e8ec0d69f4d1c8f43c3fc55.zip
gdb-6d01333390a0047a4e8ec0d69f4d1c8f43c3fc55.tar.gz
gdb-6d01333390a0047a4e8ec0d69f4d1c8f43c3fc55.tar.bz2
From Craig Silverstein: size hash tables to avoid resizing.
Diffstat (limited to 'gold/layout.cc')
-rw-r--r--gold/layout.cc19
1 files changed, 19 insertions, 0 deletions
diff --git a/gold/layout.cc b/gold/layout.cc
index 26585fa..1cea1a6 100644
--- a/gold/layout.cc
+++ b/gold/layout.cc
@@ -1154,6 +1154,25 @@ Layout::set_section_indexes(unsigned int shndx)
void
Layout::count_local_symbols(const Input_objects* input_objects)
{
+ // First, figure out an upper bound on the number of symbols we'll
+ // be inserting into each pool. This helps us create the pools with
+ // the right size, to avoid unnecessary hashtable resizing.
+ unsigned int symbol_count = 0;
+ for (Input_objects::Relobj_iterator p = input_objects->relobj_begin();
+ p != input_objects->relobj_end();
+ ++p)
+ symbol_count += (*p)->local_symbol_count();
+
+ // Go from "upper bound" to "estimate." We overcount for two
+ // reasons: we double-count symbols that occur in more than one
+ // object file, and we count symbols that are dropped from the
+ // output. Add it all together and assume we overcount by 100%.
+ symbol_count /= 2;
+
+ // We assume all symbols will go into both the sympool and dynpool.
+ this->sympool_.reserve(symbol_count);
+ this->dynpool_.reserve(symbol_count);
+
for (Input_objects::Relobj_iterator p = input_objects->relobj_begin();
p != input_objects->relobj_end();
++p)