]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
ls: tune is_colored
authorPaul Eggert <eggert@cs.ucla.edu>
Tue, 1 Oct 2024 20:18:19 +0000 (13:18 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Thu, 3 Oct 2024 06:03:04 +0000 (23:03 -0700)
* src/ls.c (is_colored): Tune.
This shrinks the machine code considerably on x86-64.

src/ls.c

index 8599368eff67732b94385648367142ff520e4fc5..46f8e8e4134172b955f47f21c158aa36f3f52718 100644 (file)
--- 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