]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
uniq: replace a wasteful loop with simple calculation
authorJim Meyering <meyering@redhat.com>
Mon, 17 Jan 2011 11:36:58 +0000 (12:36 +0100)
committerJim Meyering <meyering@redhat.com>
Mon, 17 Jan 2011 18:07:58 +0000 (19:07 +0100)
* src/uniq.c (find_field): Remove the byte-skipping loop altogether.
Instead, perform the simple calculation.  This results in a 10%
performance improvement for large byte offsets.

src/uniq.c

index 9c7e37c7b9b29cc8d6c2142d7c5cfc694754cc5a..b35938a19cb417b1c8494b992f77e5ec1125096b 100644 (file)
@@ -222,8 +222,7 @@ find_field (struct linebuffer const *line)
         i++;
     }
 
-  for (count = 0; count < skip_chars && i < size; count++)
-    i++;
+  i += MIN (skip_chars, size - i);
 
   return line->buffer + i;
 }