git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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

From
Thomas Spura <tomspur@fedoraproject.org>
Date
May 25, 2009, 19:44 UTC
Message-ID
<pan.2009.05.25.19.44.10@fedoraproject.org>
Move a char and a char * outside of a for loop for speed improvements
Signed-off-by: Thomas Spura <tomspur@fedoraproject.org>
---
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;
-
 		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);
 	return 0;
 }
 
-- 
1.6.0.6
Next: Björn Steinbrink
Message 1 of 7 in “speed: reuse char instead of recreation in loop”
  1. speed: reuse char instead of recreation in loopThomas Spura, May 25, 2009
  2. Björn SteinbrinkMay 25, 2009
  3. Thomas SpuraMay 25, 2009
  4. Daniel BarkalowMay 25, 2009
  5. Stephen R. van den BergMay 26, 2009
  6. René ScharfeMay 25, 2009
  7. Thomas SpuraMay 25, 2009

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.