[PATCH util/makedepend 3/3] Simplify writing of output lines to Makefile

Alan Coopersmith alan.coopersmith at oracle.com
Sat May 5 18:11:58 UTC 2018


Instead of writing everything to a temporary buffer, and then using
fwrite() to have it fputc() one character at a time into the stdio
buffer, just use fprintf() directly to save a copy and write in
larger blocks.

Testing on Solaris on makedepend's own source files showed a
reduction in memcpy's from 4037 to 3108, and in _dowrite calls
in stdio from 1173 to 168, but no change in actual write calls
from stdio's buffer to the file.

Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>
---
 pr.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/pr.c b/pr.c
index 9a49635..4744d56 100644
--- a/pr.c
+++ b/pr.c
@@ -108,7 +108,6 @@ pr(struct inclist *ip, const char *file, const char *base)
 	static int	current_len;
 	register int	len, i;
 	const char *	quoted;
-	char	buf[ BUFSIZ ];
 	char	quotebuf[ BUFSIZ ];
 
 	printed = TRUE;
@@ -116,15 +115,13 @@ pr(struct inclist *ip, const char *file, const char *base)
 	len = strlen(quoted)+1;
 	if (current_len + len > width || file != lastfile) {
 		lastfile = file;
-		snprintf(buf, sizeof(buf), "\n%s%s%s: %s",
+		current_len = fprintf(stdout, "\n%s%s%s: %s",
 			 objprefix, base, objsuffix, quoted);
-		len = current_len = strlen(buf);
 	}
 	else {
-		snprintf(buf, sizeof(buf), " %s", quoted);
+		fprintf(stdout, " %s", quoted);
 		current_len += len;
 	}
-	fwrite(buf, len, 1, stdout);
 
 	/*
 	 * If verbose is set, then print out what this file includes.
-- 
2.15.0



More information about the xorg-devel mailing list