From 8605284e0d1b70d9845ca4c6362d7d451f503d32 Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Mon, 3 Oct 2011 10:54:08 -0500 Subject: Use puts() instead of no-op printf() where applicable This replaces several printf calls of the following styles: printf("%s", ...); printf("some fixed string"); printf("x"); We can use either fputs() or putchar() here to do the same thing without incurring the overhead of the printf format parser. The biggest gain here comes when we are calling the print function in a loop repeatedly; notably when printing local package files. $ /usr/bin/time ./pacman-before -Ql | md5sum 0.25user 0.04system 0:00.30elapsed 98%CPU $ /usr/bin/time ./pacman-after -Ql | md5sum 0.17user 0.06system 0:00.25elapsed 94%CPU $ /usr/bin/time ./pacman-before -Qlq | md5sum 0.20user 0.05system 0:00.26elapsed 98%CPU $ /usr/bin/time ./pacman-after -Qlq | md5sum 0.15user 0.05system 0:00.23elapsed 93%CPU So '-Ql' shows a 17% improvement while '-Qlq' shows a 13% improvement on 382456 total files. Signed-off-by: Dan McGee --- src/pacman/package.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'src/pacman/package.c') diff --git a/src/pacman/package.c b/src/pacman/package.c index 49509571..f82be470 100644 --- a/src/pacman/package.c +++ b/src/pacman/package.c @@ -252,11 +252,16 @@ void dump_pkg_files(alpm_pkg_t *pkg, int quiet) for(i = 0; i < pkgfiles->count; i++) { const alpm_file_t *file = pkgfiles->files + i; + /* Regular: ' \n' + * Quiet : '\n' + */ if(!quiet) { - fprintf(stdout, "%s %s%s\n", pkgname, root, file->name); - } else { - fprintf(stdout, "%s%s\n", root, file->name); + fputs(pkgname, stdout); + putchar(' '); } + fputs(root, stdout); + fputs(file->name, stdout); + putchar('\n'); } fflush(stdout); @@ -281,10 +286,10 @@ void dump_pkg_changelog(alpm_pkg_t *pkg) /* if we hit the end of the file, we need to add a null terminator */ *(buf + ret) = '\0'; } - printf("%s", buf); + fputs(buf, stdout); } alpm_pkg_changelog_close(pkg, fp); - printf("\n"); + putchar('\n'); } } -- cgit v1.2.3-24-g4f1b