]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
(different): Don't assume that lengths can fit
authorJim Meyering <jim@meyering.net>
Sat, 25 Aug 2001 09:19:59 +0000 (09:19 +0000)
committerJim Meyering <jim@meyering.net>
Sat, 25 Aug 2001 09:19:59 +0000 (09:19 +0000)
into size_t.  Tune code for the common case where the line
lengths differ: we avoid comparing them entirely in that case.

src/uniq.c

index 4f870bf3d99a7f7ce43d8181e5168be4c6481c93..2fae7a53d688734a86fd17e6a11b7db29bb8ef02 100644 (file)
@@ -207,24 +207,21 @@ find_field (const struct linebuffer *line)
 static int
 different (const char *old, const char *new, size_t oldlen, size_t newlen)
 {
-  register int order;
-
   if (check_chars < oldlen)
     oldlen = check_chars;
   if (check_chars < newlen)
     newlen = check_chars;
 
+  if (oldlen != newlen)
+    return 1;
+
   /* Use an if-statement here rather than a function variable to
      avoid portability hassles of getting a non-conflicting declaration
      of memcmp.  */
   if (ignore_case)
-    order = memcasecmp (old, new, MIN (oldlen, newlen));
+    return memcasecmp (old, new, oldlen);
   else
-    order = memcmp (old, new, MIN (oldlen, newlen));
-
-  if (order == 0)
-    return oldlen - newlen;
-  return order;
+    return memcmp (old, new, oldlen);
 }
 
 /* Output the line in linebuffer LINE to stream STREAM