optimizing...
replace printf with fwrite to make it ever so slightly faster
This commit is contained in:
28
XD.c
28
XD.c
@ -9,6 +9,8 @@
|
|||||||
#include <git2.h>
|
#include <git2.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#define P(X) fwrite(X, 1, 1, stdout)
|
||||||
|
|
||||||
#ifdef ERR
|
#ifdef ERR
|
||||||
void
|
void
|
||||||
l(const char *fmt, ...)
|
l(const char *fmt, ...)
|
||||||
@ -182,25 +184,25 @@ main(int argc, char *argv[])
|
|||||||
if (git_ok) {
|
if (git_ok) {
|
||||||
/* change the eyes depending on the current git repo's status */
|
/* change the eyes depending on the current git repo's status */
|
||||||
if (has_stashes(repo)) {
|
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)) {
|
} 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 {
|
} 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 */
|
/* change the nose depending on the current git repo's status */
|
||||||
if (has_staged(repo)) {
|
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)) {
|
} 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)) {
|
} 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
|
} else
|
||||||
#endif
|
#endif
|
||||||
if (1) {
|
if (1) {
|
||||||
printf(":");
|
P(":");
|
||||||
}
|
}
|
||||||
|
|
||||||
/* get exit code from user args */
|
/* get exit code from user args */
|
||||||
@ -211,14 +213,14 @@ main(int argc, char *argv[])
|
|||||||
/* change mouth based on exit code */
|
/* change mouth based on exit code */
|
||||||
if (code >= 0) {
|
if (code >= 0) {
|
||||||
switch (code) {
|
switch (code) {
|
||||||
case 0: printf(")"); break; /* all good */
|
case 0: P(")"); break; /* all good */
|
||||||
case 130: printf("O"); break; /* Ctrl-c pressed (SIGTERM) */
|
case 130: P("O"); break; /* Ctrl-c pressed (SIGTERM) */
|
||||||
case 126: printf("P"); break; /* permission denied */
|
case 126: P("P"); break; /* permission denied */
|
||||||
case 127: printf("/"); break; /* command not found */
|
case 127: P("/"); break; /* command not found */
|
||||||
default: printf("("); break; /* all other codes (usually the program saying it has failed) */
|
default: P("("); break; /* all other codes (usually the program saying it has failed) */
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
printf("|"); /* no code info */
|
P("|"); /* no code info */
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef GIT
|
#ifdef GIT
|
||||||
|
Reference in New Issue
Block a user