From 876c3f43abcb9726c23584a607a98a3ad225c7be Mon Sep 17 00:00:00 2001 From: Ruben Gonzalez Date: Fri, 16 Feb 2024 22:55:03 +0100 Subject: [PATCH] logger: minor performance improvement to avoid syscall done by isatty --- spa/plugins/support/logger.c | 2 +- src/tools/pw-config.c | 2 +- src/tools/pw-dump.c | 2 +- src/tools/pw-mon.c | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/spa/plugins/support/logger.c b/spa/plugins/support/logger.c index 6b59919f3..a1bababc2 100644 --- a/spa/plugins/support/logger.c +++ b/spa/plugins/support/logger.c @@ -370,7 +370,7 @@ impl_init(const struct spa_handle_factory *factory, if (linebuf) setlinebuf(this->file); - if (!isatty(fileno(this->file)) && !force_colors) { + if (this->colors && !force_colors && !isatty(fileno(this->file)) ) { this->colors = false; } diff --git a/src/tools/pw-config.c b/src/tools/pw-config.c index abdb656e5..8e0e23cb1 100644 --- a/src/tools/pw-config.c +++ b/src/tools/pw-config.c @@ -154,7 +154,7 @@ int main(int argc, char *argv[]) d.opt_prefix = NULL; d.opt_recurse = false; d.opt_newline = true; - if (isatty(fileno(stdout)) && getenv("NO_COLOR") == NULL) + if (getenv("NO_COLOR") == NULL && isatty(fileno(stdout))) d.opt_colors = true; d.opt_cmd = "paths"; diff --git a/src/tools/pw-dump.c b/src/tools/pw-dump.c index f2b7b3ba5..066685f90 100644 --- a/src/tools/pw-dump.c +++ b/src/tools/pw-dump.c @@ -1541,7 +1541,7 @@ int main(int argc, char *argv[]) pw_init(&argc, &argv); data.out = stdout; - if (isatty(fileno(data.out)) && getenv("NO_COLOR") == NULL) + if (getenv("NO_COLOR") == NULL && isatty(fileno(data.out))) colors = true; setlinebuf(data.out); diff --git a/src/tools/pw-mon.c b/src/tools/pw-mon.c index 9fa9e6c13..0f57d4d02 100644 --- a/src/tools/pw-mon.c +++ b/src/tools/pw-mon.c @@ -786,7 +786,7 @@ int main(int argc, char *argv[]) setlinebuf(stdout); - if (isatty(STDOUT_FILENO) && getenv("NO_COLOR") == NULL) + if (getenv("NO_COLOR") == NULL && isatty(STDOUT_FILENO)) colors = true; while ((c = getopt_long(argc, argv, "hVr:NCoa", long_options, NULL)) != -1) {