This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [patch] Refactor duplicated code into a helper function


> 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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]