commit:     c700e6d63ab7d32bcbcc42ac4b7497d4c50cb4dc
Author:     Kerin Millar <kfm <AT> plushkava <DOT> net>
AuthorDate: Sat Jan 10 00:43:16 2026 +0000
Commit:     Kerin Millar <kfm <AT> plushkava <DOT> net>
CommitDate: Sat Jan 10 00:43:16 2026 +0000
URL:        https://gitweb.gentoo.org/proj/locale-gen.git/commit/?id=c700e6d6

Avoid repeated isatty(3) calls in print_warning()

Presently, the print_warning() subroutine checks whether STDERR is a
terminal on each and every occasion that is called. Optimise the
subroutine by caching the result of the first check. Note that
locale-gen(8) is not a library; where STDERR is found to be a terminal,
it can be assumed that it shall remain one until execution is concluded.

Signed-off-by: Kerin Millar <kfm <AT> plushkava.net>

 locale-gen | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/locale-gen b/locale-gen
index 905fdef..ddb44ce 100644
--- a/locale-gen
+++ b/locale-gen
@@ -743,7 +743,8 @@ sub can_run ($bin) {
 }
 
 sub print_warning ($warning) {
-       if (-t 2) {
+       state $is_tty = -t 2;
+       if ($is_tty) {
                local $Term::ANSIColor::EACHLINE = "\n";
                print STDERR colored($warning, 'bold yellow');
        } else {

Reply via email to