bug-diffutils
[Top][All Lists]
Advanced

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

[bug-diffutils] bug#33144: bug#33144: Replace some loops with str functi


From: Kapus, Timotej
Subject: [bug-diffutils] bug#33144: bug#33144: Replace some loops with str functions
Date: Fri, 26 Oct 2018 09:51:45 +0000

Thanks for your reply and apologies for sending a buggy patch. Yes I agree it's probably slower, but I doubt it has significant impact on the whole runtime. The insignifcant slowdown might be worth it, if you would find the code much clearer. In any case, I'm attaching an updated version of the patch, where I  proved c and c1 are eqvivalent at the end, up to the bound of 5 bytes, so should be fine this time.


From 4911d9676f1914fb4691061887396f2b21a0d036 Mon Sep 17 00:00:00 2001
From: Timotej Kapus <address@hidden>
Date: Wed, 24 Oct 2018 23:47:22 +0100
Subject: [PATCH] maint: change 3 loops to strspn calls

  * src/ifdef.c: Change 3 loops to equivalent calls to strspn
---
 src/ifdef.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/src/ifdef.c b/src/ifdef.c
index 0ecc2c0..4533e3a 100644
--- a/src/ifdef.c
+++ b/src/ifdef.c
@@ -313,13 +313,13 @@ do_printf_spec (FILE *out, char const *spec,
   /* Scan printf-style SPEC of the form %[-'0]*[0-9]*(.[0-9]*)?[cdoxX].  */
   /* assert (*f == '%'); */
   f++;
-  while ((c = *f++) == '-' || c == '\'' || c == '0')
-    continue;
-  while (ISDIGIT (c))
-    c = *f++;
-  if (c == '.')
-    while (ISDIGIT (c = *f++))
-      continue;
+  f += strspn(f, "-\'0") + 1;
+  if(ISDIGIT(c = *(f - 1)))
+    f += strspn(f, "0123456789") + 1;
+  if ((c = *(f - 1)) == '.') {
+    f += strspn(f, "0123456789") + 1;
+    c = *(f - 1);
+  }
   c1 = *f++;
 
   switch (c)
-- 
2.7.4



Od: Paul Eggert <address@hidden>
Poslano: Ĩetrtek, 25. oktober 2018 20:57:10
Za: Kapus, Timotej; address@hidden
Kp: Cadar, Cristian
Zadeva: Re: [bug-diffutils] bug#33144: Replace some loops with str functions
 
On 10/24/18 4:06 PM, Kapus, Timotej wrote:
> I find strspn easier to read, communicate intention and has less LOC

On the other hand, it's probably slower for this particular use case,
and the replacement code you wrote is not equivalent to the code it
replaced because 'c' ends up having a different value.


reply via email to

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