We don't need a hash table mapping input locations to strings.

This commit is contained in:
Ian Lance Taylor
2007-09-22 05:38:12 +00:00
parent e214a02b9b
commit 42e3fe0dd9
2 changed files with 19 additions and 56 deletions

View File

@ -208,32 +208,6 @@ Output_merge_data::do_write(Output_file* of)
of->write(this->offset(), this->p_, this->len_); of->write(this->offset(), this->p_, this->len_);
} }
// Compute a hash code for a Merge_string_key, which is an object, a
// section index, and an offset.
template<typename Char_type>
size_t
Output_merge_string<Char_type>::Merge_string_key_hash::operator()(
const Merge_string_key& key) const
{
// This is a very simple minded hash code. Fix it if it we get too
// many collisions.
const std::string& oname(key.object->name());
return oname[0] + oname.length() + key.shndx + key.offset;
}
// Compare two Merge_string_keys for equality.
template<typename Char_type>
bool
Output_merge_string<Char_type>::Merge_string_key_eq::operator()(
const Merge_string_key& k1, const Merge_string_key& k2) const
{
return (k1.object == k2.object
&& k1.shndx == k2.shndx
&& k1.offset == k2.offset);
}
// Add an input section to a merged string section. // Add an input section to a merged string section.
template<typename Char_type> template<typename Char_type>
@ -275,10 +249,7 @@ Output_merge_string<Char_type>::do_add_input_section(Relobj* object,
const Char_type* str = this->stringpool_.add(p, NULL); const Char_type* str = this->stringpool_.add(p, NULL);
Merge_string_key k(object, shndx, i); this->merged_strings_.push_back(Merged_string(object, shndx, i, str));
typename Merge_string_hashtable::value_type v(k, str);
bool b = this->hashtable_.insert(v).second;
gold_assert(b);
p += plen + 1; p += plen + 1;
i += plen + 1; i += plen + 1;
@ -297,17 +268,17 @@ Output_merge_string<Char_type>::do_set_address(uint64_t, off_t)
{ {
this->stringpool_.set_string_offsets(); this->stringpool_.set_string_offsets();
for (typename Merge_string_hashtable::const_iterator p = for (typename Merged_strings::const_iterator p =
this->hashtable_.begin(); this->merged_strings_.begin();
p != this->hashtable_.end(); p != this->merged_strings_.end();
++p) ++p)
this->add_mapping(p->first.object, p->first.shndx, p->first.offset, this->add_mapping(p->object, p->shndx, p->offset,
this->stringpool_.get_offset(p->second)); this->stringpool_.get_offset(p->string));
this->set_data_size(this->stringpool_.get_strtab_size()); this->set_data_size(this->stringpool_.get_strtab_size());
// Save some memory. // Save some memory.
this->hashtable_.clear(); this->merged_strings_.clear();
} }
// Write out a merged string section. // Write out a merged string section.

View File

@ -169,7 +169,7 @@ class Output_merge_string : public Output_merge_base
{ {
public: public:
Output_merge_string() Output_merge_string()
: Output_merge_base(sizeof(Char_type)), stringpool_(), hashtable_() : Output_merge_base(sizeof(Char_type)), stringpool_(), merged_strings_()
{ this->stringpool_.set_no_zero_null(); } { this->stringpool_.set_no_zero_null(); }
// Add an input section. // Add an input section.
@ -187,38 +187,30 @@ class Output_merge_string : public Output_merge_base
private: private:
// As we see input sections, we build a mapping from object, section // As we see input sections, we build a mapping from object, section
// index and offset to strings. // index and offset to strings.
struct Merge_string_key struct Merged_string
{ {
// The input object where the string was found.
Relobj* object; Relobj* object;
// The input section in the input object.
unsigned int shndx; unsigned int shndx;
// The offset in the input section.
off_t offset; off_t offset;
// The string itself, a pointer into a Stringpool.
const Char_type* string;
Merge_string_key(Relobj *objecta, unsigned int shndxa, off_t offseta) Merged_string(Relobj *objecta, unsigned int shndxa, off_t offseta,
: object(objecta), shndx(shndxa), offset(offseta) const Char_type* stringa)
: object(objecta), shndx(shndxa), offset(offseta), string(stringa)
{ } { }
}; };
struct Merge_string_key_hash typedef std::vector<Merged_string> Merged_strings;
{
size_t
operator()(const Merge_string_key&) const;
};
struct Merge_string_key_eq
{
bool
operator()(const Merge_string_key&, const Merge_string_key&) const;
};
typedef Unordered_map<Merge_string_key, const Char_type*,
Merge_string_key_hash, Merge_string_key_eq>
Merge_string_hashtable;
// As we see the strings, we add them to a Stringpool. // As we see the strings, we add them to a Stringpool.
Stringpool_template<Char_type> stringpool_; Stringpool_template<Char_type> stringpool_;
// Map from a location in an input object to an entry in the // Map from a location in an input object to an entry in the
// Stringpool. // Stringpool.
Merge_string_hashtable hashtable_; Merged_strings merged_strings_;
}; };
} // End namespace gold. } // End namespace gold.