mirror of
https://github.com/moparisthebest/pacman
synced 2025-03-01 01:41:52 -05:00
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 <dan@archlinux.org>
This commit is contained in:
parent
9934052b54
commit
8605284e0d
@ -228,7 +228,7 @@ void cb_event(alpm_event_t event, void *data1, void *data2)
|
||||
printf(_("failed.\n"));
|
||||
break;
|
||||
case ALPM_EVENT_SCRIPTLET_INFO:
|
||||
printf("%s", (char *)data1);
|
||||
fputs((const char *)data1, stdout);
|
||||
break;
|
||||
case ALPM_EVENT_RETRIEVE_START:
|
||||
printf(_(":: Retrieving packages from %s...\n"), (char *)data1);
|
||||
@ -495,7 +495,7 @@ void cb_progress(alpm_progress_t event, const char *pkgname, int percent,
|
||||
alpm_list_t *i = NULL;
|
||||
on_progress = 0;
|
||||
for(i = output; i; i = i->next) {
|
||||
printf("%s", (char *)i->data);
|
||||
fputs((const char *)i->data, stdout);
|
||||
}
|
||||
fflush(stdout);
|
||||
FREELIST(output);
|
||||
|
@ -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: '<pkgname> <root><filepath>\n'
|
||||
* Quiet : '<root><filepath>\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');
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -208,7 +208,7 @@ static void usage(int op, const char * const myname)
|
||||
}
|
||||
list = alpm_list_msort(list, alpm_list_count(list), options_cmp);
|
||||
for (i = list; i; i = alpm_list_next(i)) {
|
||||
printf("%s", (const char *)i->data);
|
||||
fputs((const char *)i->data, stdout);
|
||||
}
|
||||
alpm_list_free(list);
|
||||
#undef addlist
|
||||
|
@ -268,23 +268,23 @@ static int query_search(alpm_list_t *targets)
|
||||
if(!config->quiet) {
|
||||
printf("local/%s %s", alpm_pkg_get_name(pkg), alpm_pkg_get_version(pkg));
|
||||
} else {
|
||||
printf("%s", alpm_pkg_get_name(pkg));
|
||||
fputs(alpm_pkg_get_name(pkg), stdout);
|
||||
}
|
||||
|
||||
|
||||
if(!config->quiet) {
|
||||
if((grp = alpm_pkg_get_groups(pkg)) != NULL) {
|
||||
alpm_list_t *k;
|
||||
printf(" (");
|
||||
fputs(" (", stdout);
|
||||
for(k = grp; k; k = alpm_list_next(k)) {
|
||||
const char *group = k->data;
|
||||
printf("%s", group);
|
||||
fputs(group, stdout);
|
||||
if(alpm_list_next(k)) {
|
||||
/* only print a spacer if there are more groups */
|
||||
printf(" ");
|
||||
putchar(' ');
|
||||
}
|
||||
}
|
||||
printf(")");
|
||||
putchar(')');
|
||||
}
|
||||
|
||||
/* we need a newline and initial indent first */
|
||||
|
@ -359,22 +359,22 @@ static int sync_search(alpm_list_t *syncs, alpm_list_t *targets)
|
||||
printf("%s/%s %s", alpm_db_get_name(db), alpm_pkg_get_name(pkg),
|
||||
alpm_pkg_get_version(pkg));
|
||||
} else {
|
||||
printf("%s", alpm_pkg_get_name(pkg));
|
||||
fputs(alpm_pkg_get_name(pkg), stdout);
|
||||
}
|
||||
|
||||
if(!config->quiet) {
|
||||
if((grp = alpm_pkg_get_groups(pkg)) != NULL) {
|
||||
alpm_list_t *k;
|
||||
printf(" (");
|
||||
fputs(" (", stdout);
|
||||
for(k = grp; k; k = alpm_list_next(k)) {
|
||||
const char *group = k->data;
|
||||
printf("%s", group);
|
||||
fputs(group, stdout);
|
||||
if(alpm_list_next(k)) {
|
||||
/* only print a spacer if there are more groups */
|
||||
printf(" ");
|
||||
putchar(' ');
|
||||
}
|
||||
}
|
||||
printf(")");
|
||||
putchar(')');
|
||||
}
|
||||
|
||||
print_installed(db_local, pkg);
|
||||
|
@ -266,7 +266,7 @@ void indentprint(const char *str, size_t indent)
|
||||
/* if we're not a tty, or our tty is not wide enough that wrapping even makes
|
||||
* sense, print without indenting */
|
||||
if(cols == 0 || indent > cols) {
|
||||
printf("%s", str);
|
||||
fputs(str, stdout);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -623,7 +623,7 @@ void list_display(const char *title, const alpm_list_t *list)
|
||||
const unsigned short maxcols = getcols();
|
||||
size_t cols = len;
|
||||
const char *str = list->data;
|
||||
printf("%s", str);
|
||||
fputs(str, stdout);
|
||||
cols += string_length(str);
|
||||
for(i = alpm_list_next(list); i; i = alpm_list_next(i)) {
|
||||
str = i->data;
|
||||
@ -641,10 +641,10 @@ void list_display(const char *title, const alpm_list_t *list)
|
||||
printf(" ");
|
||||
cols += 2;
|
||||
}
|
||||
printf("%s", str);
|
||||
fputs(str, stdout);
|
||||
cols += s;
|
||||
}
|
||||
printf("\n");
|
||||
putchar('\n');
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user