login
Header Space

 
 

Re: [PATCH 3/3] pretty=format: Avoid some expensive calculations when not needed

Score:
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
To: René Scharfe <rene.scharfe@...>
Cc: Junio C Hamano <gitster@...>, <git@...>
Date: Monday, November 5, 2007 - 7:53 pm

Hi,

On Mon, 5 Nov 2007, Ren? Scharfe wrote:


Yeah, something like this on top of my earlier patch (and obviously the 
corresponding change from "if (active[IHASH])" to
"if (table[IHASH].value)"):

---

 interpolate.c |   10 ++++------
 interpolate.h |    2 +-
 2 files changed, 5 insertions(+), 7 deletions(-)

diff --git a/interpolate.c b/interpolate.c
index 80eeb36..05a22e1 100644
--- a/interpolate.c
+++ b/interpolate.c
@@ -5,13 +5,14 @@
 #include "git-compat-util.h"
 #include "interpolate.h"
 
+static const char *empty_value = "";
 
 void interp_set_entry(struct interp *table, int slot, const char *value)
 {
 	char *oldval = table[slot].value;
 	char *newval = NULL;
 
-	if (oldval)
+	if (oldval && oldval != empty_value)
 		free(oldval);
 
 	if (value)
@@ -103,10 +104,9 @@ unsigned long interpolate(char *result, unsigned long reslen,
 	return newlen;
 }
 
-char *interp_find_active(const char *orig,
+void interp_find_active(const char *orig,
 		const struct interp *interps, int ninterps)
 {
-	char *result = xcalloc(1, ninterps);
 	char c;
 	int i;
 
@@ -115,10 +115,8 @@ char *interp_find_active(const char *orig,
 			/* Try to match an interpolation string. */
 			for (i = 0; i < ninterps; i++)
 				if (!prefixcmp(orig, interps[i].name + 1)) {
-					result[i] = 1;
+					interps[i].value = empty_value;
 					orig += strlen(interps[i].name + 1);
 					break;
 				}
-
-	return result;
 }
diff --git a/interpolate.h b/interpolate.h
index 2d197c5..19b7ebe 100644
--- a/interpolate.h
+++ b/interpolate.h
@@ -22,7 +22,7 @@ extern void interp_clear_table(struct interp *table, int ninterps);
 extern unsigned long interpolate(char *result, unsigned long reslen,
 				 const char *orig,
 				 const struct interp *interps, int ninterps);
-extern char *interp_find_active(const char *orig,
+extern void interp_find_active(const char *orig,
 				const struct interp *interps, int ninterps);
 
 #endif /* INTERPOLATE_H */


Hmm?

Ciao,
Dscho

-
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
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[PATCH 0/3] Make user formatted commit listing less expensive, Johannes Schindelin, (Sun Nov 4, 3:14 pm)
[PATCH 3/3] pretty=format: Avoid some expensive calculations..., Johannes Schindelin, (Sun Nov 4, 3:15 pm)
Re: [PATCH 3/3] pretty=format: Avoid some expensive calculat..., Johannes Schindelin, (Tue Nov 6, 7:36 pm)
[PATCH 2/2] pretty=format: Avoid some expensive calculations..., Johannes Schindelin, (Tue Nov 6, 7:38 pm)
[PATCH 1/2] interpolate.[ch]: Add a function to find which i..., Johannes Schindelin, (Tue Nov 6, 7:38 pm)
Re: [PATCH 3/3] pretty=format: Avoid some expensive calculat..., Johannes Schindelin, (Tue Nov 6, 7:45 pm)
Re: [PATCH 3/3] pretty=format: Avoid some expensive calculat..., Johannes Schindelin, (Wed Nov 7, 8:14 pm)
Re: [PATCH 3/3] pretty=format: Avoid some expensive calculat..., Johannes Schindelin, (Mon Nov 5, 7:53 pm)
[PATCH 2/3] interpolate.[ch]: Add a function to find which i..., Johannes Schindelin, (Sun Nov 4, 3:15 pm)
[PATCH 1/3] Split off the pretty print stuff into its own file, Johannes Schindelin, (Sun Nov 4, 3:15 pm)
speck-geostationary