This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] Refactoring: use std::swap instead of manual swaps
- From: Trevor Saunders <tbsaunde at tbsaunde dot org>
- To: Mikhail Maltsev <maltsevm at gmail dot com>
- Cc: gcc-patches <gcc-patches at gnu dot org>
- Date: Mon, 18 May 2015 16:05:19 -0400
- Subject: Re: [PATCH] Refactoring: use std::swap instead of manual swaps
- Authentication-results: sourceware.org; auth=none
- References: <555A2A6F dot 8080705 at gmail dot com>
On Mon, May 18, 2015 at 09:07:43PM +0300, Mikhail Maltsev wrote:
> Hi all.
> The attached patch replaces the following typical sequence of
> assignments, matching the pattern:
>
> [type] <temp_var> = <value1>;
> <value1> = <value2>;
> <value2> = <temp_var>;
>
> with
>
> std::swap (<value1>, <value2>);
I believe that transformation is considered obvious, so you can just go
ahead and commit all the parts that are just that. That should make
reviewers lives much simpler ;-)
> The goal is to improve code readability (at least a little).
>
> Pattern was searched in GCC tree using a script, but all modifications
> have been done manually to make sure that removing assignment to
> <temp_var> does not modify the behavior of the code. Where possible,
> temporary variables were removed or moved to blocks with narrower scope.
> I also removed a couple of pre-C++ implementations of swap function and
> one implementation of std::reverse.
I haven't looked at the cases where you removed functions, but I suspect
you can call those obvious too, and save yourself any rebasing pain.
thanks!
Trev