This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: [gold][patch] Reduce heap usage for string merge sections
Cary Coutant <ccoutant@google.com> writes:
> * merge.cc (Output_merge_string::do_add_input_section): Count strings
> to reserve space in merged_strings vector. Keep total input size
> for stats.
> (Output_merge_string::do_print_merge_stats): Print total input size.
> * merge.h (Output_merge_string): Add input_size_ field.
> + // Count the number of strings in the section and size the list.
> + size_t count = 0;
> + for (const Char_type* pl = p; pl < pend; ++pl)
> + {
> + if (*pl == 0)
> + ++count;
> + }
In the case where Char_type is char, I have a feeling this loop would be
a tiny bit faster if written as
const Char_type* pl = p;
while (pl < pend)
{
pl += strlen(pl) + 1;
if (pl > pend)
warning(...);
++count;
}
This is simply because the compiler will optimize strlen for the
specific compilation target. See
Stringpool_template<char>::string_length for a similar optimization in
the Stringpool code.
Also, since you have the exact count, it would be a tiny bit better to
allocate the vector at that size rather than allocating a default vector
and then using reserve. You could this by adding a parameter to the
Merged_strings_list constructor which is passed to merged_strings.
This is OK with or without those changes.
Thanks.
Ian