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

Submitted by Alan Coopersmith on May 5, 2018, 6:11 p.m.

Details

Message ID 20180505181158.16819-3-alan.coopersmith@oracle.com
State Accepted
Commit d15117c98a071b8fd30fb163fc45cb37db760654
Headers show
Series "Series without cover letter" ( rev: 1 ) in X.org (DEPRECATED - USE GITLAB)

Not browsing as part of any series.

Commit Message

Alan Coopersmith May 5, 2018, 6:11 p.m.
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@oracle.com>
---
 pr.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)

Patch hide | download patch | download mbox

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.