From 2a6385fa36106f3fc9c23b705a3cca1d31f196f5 Mon Sep 17 00:00:00 2001 From: Squibid Date: Thu, 19 Dec 2024 13:41:57 -0600 Subject: optimizing... replace printf with fwrite to make it ever so slightly faster --- XD.c | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/XD.c b/XD.c index 31c1dd1..92c3095 100644 --- a/XD.c +++ b/XD.c @@ -9,6 +9,8 @@ #include #endif +#define P(X) fwrite(X, 1, 1, stdout) + #ifdef ERR void l(const char *fmt, ...) @@ -182,25 +184,25 @@ main(int argc, char *argv[]) if (git_ok) { /* change the eyes depending on the current git repo's status */ if (has_stashes(repo)) { - printf("8"); /* goggle eyes if we have some stashed changes */ + P("8"); /* goggle eyes if we have some stashed changes */ } else if (git_repository_is_empty(repo)) { - printf("B"); /* sunglasses if we're in a new repo with no HEAD */ + P("B"); /* sunglasses if we're in a new repo with no HEAD */ } else { - printf(";"); /* wink when we're in a git repo */ + P(";"); /* wink when we're in a git repo */ } /* change the nose depending on the current git repo's status */ if (has_staged(repo)) { - printf("*"); /* change to broken nose for staged changes */ + P("*"); /* change to broken nose for staged changes */ } else if (has_untracked(repo)) { - printf("^"); /* add a little nose when there are untracked changes in the repo */ + P("^"); /* add a little nose when there are untracked changes in the repo */ } else if (git_repository_head_detached(repo)) { - printf("-"); /* add a minus nose when the HEAD is detached */ + P("-"); /* add a minus nose when the HEAD is detached */ } } else #endif if (1) { - printf(":"); + P(":"); } /* get exit code from user args */ @@ -211,14 +213,14 @@ main(int argc, char *argv[]) /* change mouth based on exit code */ if (code >= 0) { switch (code) { - case 0: printf(")"); break; /* all good */ - case 130: printf("O"); break; /* Ctrl-c pressed (SIGTERM) */ - case 126: printf("P"); break; /* permission denied */ - case 127: printf("/"); break; /* command not found */ - default: printf("("); break; /* all other codes (usually the program saying it has failed) */ + case 0: P(")"); break; /* all good */ + case 130: P("O"); break; /* Ctrl-c pressed (SIGTERM) */ + case 126: P("P"); break; /* permission denied */ + case 127: P("/"); break; /* command not found */ + default: P("("); break; /* all other codes (usually the program saying it has failed) */ } } else { - printf("|"); /* no code info */ + P("|"); /* no code info */ } #ifdef GIT -- cgit v1.2.1