Thread (7 messages) flat view 7 messages, 5 authors, 2016-06-15

Re: [PATCH] speed: reuse char instead of recreation in loop

From: Thomas Spura <hidden>
Date: 2016-06-15 22:46:49

Am Mon, 25 May 2009 22:16:02 +0200 schrieb Björn Steinbrink:
On 2009.05.25 19:44:10 +0000, Thomas Spura wrote:
quoted
Move a char and a char * outside of a for loop for speed improvements

Signed-off-by: Thomas Spura <redacted> ---
Comments?

 transport.c |    7 +++----
 1 files changed, 3 insertions(+), 4 deletions(-)
diff --git a/transport.c b/transport.c index 17891d5..e350937 100644
--- a/transport.c
+++ b/transport.c
@@ -263,11 +263,10 @@ static int write_refs_to_temp_dir(struct strbuf
*temp_dir,
 		int refspec_nr, const char **refspec)
 {
 	int i;
+	unsigned char sha1[20];
+	char *ref;
 
 	for (i = 0; i < refspec_nr; i++) {
-		unsigned char sha1[20];
-		char *ref;
-
I doubt that this makes any difference at all.
With ints, the loop costs about 40% of speed. Without recreation, it 
should be always faster.
quoted
 		if (dwim_ref(refspec[i], strlen(refspec[i]), sha1, &ref) !
= 1)
 			return error("Could not get ref %s", refspec[i]);
 
@@ -275,8 +274,8 @@ static int write_refs_to_temp_dir(struct strbuf
*temp_dir,
 			free(ref);
 			return -1;
 		}
-		free(ref);
 	}
+	free(ref);
And this now leaks memory.
Hmm, I don't see it atm. Where do you mean?
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help