coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] cksum: improve problematic_chars function


From: Jim Meyering
Subject: [PATCH] cksum: improve problematic_chars function
Date: Thu, 13 Jul 2023 23:54:21 -0700

Small suggested improvement:

>From c0e7e4a1d41049bbf38cf902d13746b1ab5b1e38 Mon Sep 17 00:00:00 2001
From: Jim Meyering <meyering@meta.com>
Date: Thu, 13 Jul 2023 22:29:52 -0700
Subject: [PATCH] cksum: improve problematic_chars function

* src/digest.c (problematic_chars): Implement using strcspn,
and traversing S only once, rather than once per escaped byte.
---
 src/digest.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/digest.c b/src/digest.c
index e80eb3406..60ba82e5f 100644
--- a/src/digest.c
+++ b/src/digest.c
@@ -568,7 +568,8 @@ ATTRIBUTE_PURE
 static bool
 problematic_chars (char const *s)
 {
-  return strchr (s, '\\') || strchr (s, '\n') || strchr (s, '\r');
+  size_t length = strcspn (s, "\\\n\r");
+  return s[length] != '\0';
 }

 #define ISWHITE(c) ((c) == ' ' || (c) == '\t')
-- 
2.41.0.327.gaa9166bcc0


reply via email to

[Prev in Thread] Current Thread [Next in Thread]