From: Paul Eggert Date: Tue, 1 Oct 2024 20:18:19 +0000 (-0700) Subject: ls: tune is_colored X-Git-Tag: v9.6~136 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ec0fe0d2b84c041edae97bfd291757e9d62b7fff;p=thirdparty%2Fcoreutils.git ls: tune is_colored * src/ls.c (is_colored): Tune. This shrinks the machine code considerably on x86-64. --- diff --git a/src/ls.c b/src/ls.c index 8599368eff..46f8e8e413 100644 --- a/src/ls.c +++ b/src/ls.c @@ -1464,11 +1464,14 @@ free_pending_ent (struct pending *p) static bool is_colored (enum indicator_no type) { + /* Return true unless the string is "", "0" or "00"; try to be efficient. */ size_t len = color_indicator[type].len; + if (len == 0) + return false; + if (2 < len) + return true; char const *s = color_indicator[type].string; - return ! (len == 0 - || (len == 1 && STRNCMP_LIT (s, "0") == 0) - || (len == 2 && STRNCMP_LIT (s, "00") == 0)); + return (s[0] != '0') | (s[len - 1] != '0'); } static void