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

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: René Scharfe
Date: Tuesday, November 6, 2007 - 3:31 pm

Junio C Hamano schrieb:

Not from the rational part of my brain, for sure.  The following on
top of Dscho's second patch?  (A char would be smaller, but a bitfield
documents the intent better.)


diff --git a/interpolate.c b/interpolate.c
index 80eeb36..1e4ccaf 100644
--- a/interpolate.c
+++ b/interpolate.c
@@ -103,22 +103,21 @@ unsigned long interpolate(char *result, unsigned long reslen,
 	return newlen;
 }
 
-char *interp_find_active(const char *orig,
-		const struct interp *interps, int ninterps)
+void interp_find_active(const char *orig, struct interp *interps, int ninterps)
 {
-	char *result = xcalloc(1, ninterps);
 	char c;
 	int i;
 
+	for (i = 0; i < ninterps; i++)
+		interps[i].active = 0;
+
 	while ((c = *(orig++)))
 		if (c == '%')
 			/* Try to match an interpolation string. */
 			for (i = 0; i < ninterps; i++)
 				if (!prefixcmp(orig, interps[i].name + 1)) {
-					result[i] = 1;
+					interps[i].active = 1;
 					orig += strlen(interps[i].name + 1);
 					break;
 				}
-
-	return result;
 }
diff --git a/interpolate.h b/interpolate.h
index 2d197c5..a8ee6b9 100644
--- a/interpolate.h
+++ b/interpolate.h
@@ -14,6 +14,7 @@
 struct interp {
 	const char *name;
 	char *value;
+	unsigned active:1;
 };
 
 extern void interp_set_entry(struct interp *table, int slot, const char *value);
@@ -22,7 +23,6 @@ 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,
-				const struct interp *interps, int ninterps);
+extern void interp_find_active(const char *orig, struct interp *interps, int ninterps);
 
 #endif /* INTERPOLATE_H */
-
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, 12:14 pm)
[PATCH 1/3] Split off the pretty print stuff into its own file, Johannes Schindelin, (Sun Nov 4, 12:15 pm)
[PATCH 2/3] interpolate.[ch]: Add a function to find which ..., Johannes Schindelin, (Sun Nov 4, 12:15 pm)
[PATCH 3/3] pretty=format: Avoid some expensive calculatio ..., Johannes Schindelin, (Sun Nov 4, 12:15 pm)
Re: [PATCH 3/3] pretty=format: Avoid some expensive calcul ..., Johannes Schindelin, (Mon Nov 5, 4:53 pm)
Re: [PATCH 3/3] pretty=format: Avoid some expensive calcul ..., René Scharfe, (Tue Nov 6, 3:31 pm)
Re: [PATCH 3/3] pretty=format: Avoid some expensive calcul ..., Johannes Schindelin, (Tue Nov 6, 4:36 pm)
[PATCH 1/2] interpolate.[ch]: Add a function to find which ..., Johannes Schindelin, (Tue Nov 6, 4:38 pm)
[PATCH 2/2] pretty=format: Avoid some expensive calculatio ..., Johannes Schindelin, (Tue Nov 6, 4:38 pm)
Re: [PATCH 3/3] pretty=format: Avoid some expensive calcul ..., Johannes Schindelin, (Tue Nov 6, 4:45 pm)
Re: [PATCH 3/3] pretty=format: Avoid some expensive calcul ..., Johannes Schindelin, (Wed Nov 7, 5:14 pm)