Thread (1 message) 1 message, 1 author, 2016-06-15

Re: [PATCH 1/2] Remove useless temporary integer in builtin/push.c

From: Junio C Hamano <hidden>
Date: 2016-06-15 22:49:14

Jared Hance [off-list ref] writes:
Creating a variable nr here to use throughout the function only to change
refspec_nr to nr at the end, having not used refspec_nr the entire time,
is rather pointless. Instead, simply increment refspec_nr.
That is something a compiler can notice and optimize out, so it byitself
is not a good criteria to judge this change.  The real issue is if the use
of temporary makes the code easier to read or harder.

With the two patches squashed together to use ALLOC_GROW(), the result
conforms to the pattern many codepaths use, and that makes it easier to
read.

Will queue, with these two squashed into one commit.

Thanks.
quoted hunk
Signed-off-by: Jared Hance <redacted>
---
 builtin/push.c |    7 +++----
 1 files changed, 3 insertions(+), 4 deletions(-)
diff --git a/builtin/push.c b/builtin/push.c
index f4358b9..79d8192 100644
--- a/builtin/push.c
+++ b/builtin/push.c
@@ -25,10 +25,9 @@ static int refspec_nr;
 
 static void add_refspec(const char *ref)
 {
-	int nr = refspec_nr + 1;
-	refspec = xrealloc(refspec, nr * sizeof(char *));
-	refspec[nr-1] = ref;
-	refspec_nr = nr;
+	refspec_nr++;
+	refspec = xrealloc(refspec, refspec_nr * sizeof(char *));
+	refspec[refspec_nr-1] = ref;
 }
 
 static void set_refspecs(const char **refs, int nr)
-- 
1.7.2

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help