This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: [patch] Refactor duplicated code into a helper function
- From: Cary Coutant <ccoutant at google dot com>
- To: Rafael EspÃndola <rafael dot espindola at gmail dot com>
- Cc: Binutils <binutils at sourceware dot org>
- Date: Wed, 4 Feb 2015 11:13:12 -0800
- Subject: Re: [patch] Refactor duplicated code into a helper function
- Authentication-results: sourceware.org; auth=none
- References: <CAG3jReKB09wKu2tcTU7WmRHG9-88bXappSYjZSBFPaLysinovg at mail dot gmail dot com>
> 2014-09-18 Rafael Ãvila de EspÃndola <rafael.espindola@gmail.com>
> * merge.h (add_string): declare.
> * merge.cc (add_string): define.
> (do_add_input_section): use add_string.
+Output_merge_string<Char_type>::add_string(const Char_type *&p, size_t len,
+ uintptr_t init_align_modulo,
+ bool &has_misaligned_strings,
+ Merged_strings &merged_strings,
+ section_size_type &i) {
By convention, we avoid non-const reference parameters in gold. This
new method has four output parameters, and to me it's a somewhat
awkward way to refactor the code. To avoid having so many output
parameters, I'd consider introducing a small class to manage all that
state. Instead of doing that, though, I'd prefer folding the loop
epilogue back into the loop -- the only difference is the computation
of len, and we can handle that inside the loop:
while (p < pend)
{
const size_t len = p < pend0 ? string_length(p) : pend - p;
...
}
-cary