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: Rafael EspÃndola <rafael dot espindola at gmail dot com>
- To: Cary Coutant <ccoutant at google dot com>
- Cc: Binutils <binutils at sourceware dot org>
- Date: Wed, 4 Feb 2015 15:02:07 -0500
- 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> <CAHACq4qr94S6KrJu-jb4CH0UtiDrctaGXnHBsVFAKr1ZXNDuxA at mail dot gmail dot com>
> 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;
> ...
> }
Much better!
New patch attached
Thanks,
Rafael
2015-02-04 Rafael Ãvila de EspÃndola <rafael.espindola@gmail.com>
* merge.cc (do_add_input_section): combine loop epilogue into main loop body.
diff --git a/gold/merge.cc b/gold/merge.cc
index 269e6bf..f547388 100644
--- a/gold/merge.cc
+++ b/gold/merge.cc
@@ -564,9 +564,9 @@ Output_merge_string<Char_type>::do_add_input_section(Relobj* object,
& (this->addralign() - 1));
bool has_misaligned_strings = false;
- while (p < pend0)
+ while (p < pend)
{
- size_t len = string_length(p);
+ size_t len = p < pend0 ? string_length(p) : pend - p;
// Within merge input section each string must be aligned.
if (len != 0
@@ -581,17 +581,6 @@ Output_merge_string<Char_type>::do_add_input_section(Relobj* object,
p += len + 1;
i += (len + 1) * sizeof(Char_type);
}
- if (p < pend)
- {
- size_t len = pend - p;
-
- Stringpool::Key key;
- this->stringpool_.add_with_length(p, len, true, &key);
-
- merged_strings.push_back(Merged_string(i, key));
-
- i += (len + 1) * sizeof(Char_type);
- }
// Record the last offset in the input section so that we can
// compute the length of the last string.