From: Thomas Rast Date: Thu, 29 Jul 2010 22:21:33 GMT Subject: Re: [PATCH] Remove useless temporary integer in builtin/push.c Message-ID: <201007300021.34061.trast@student.ethz.ch> In-Reply-To: <70ee84752cb7db08c65c608a12ed321dd2c26830.1280419073.git.jaredhance@gmail.com> Jared Hance wrote: > 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. > > Signed-off-by: Jared Hance [...] > - 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; While you're already here, you could switch to ALLOC_GROW instead to avoid the n**2 behaviour of xrealloc... -- Thomas Rast trast@{inf,student}.ethz.ch