]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
(sort): Don't require two `struct line's per text line,
authorJim Meyering <jim@meyering.net>
Sun, 27 Jul 2003 08:28:13 +0000 (08:28 +0000)
committerJim Meyering <jim@meyering.net>
Sun, 27 Jul 2003 08:28:13 +0000 (08:28 +0000)
the new sort algorithm requires just 1.5.

src/sort.c

index 4c3a0d5d6fb6cf569b7202d3272d1f10d6c54876..24a0689b6b9a525b0fbe59c9e276428fb2f317f6 100644 (file)
@@ -1990,11 +1990,12 @@ sort (char **files, int nfiles, char const *output_file)
       char const *file = *files;
       FILE *fp = xfopen (file, "r");
       FILE *tfp;
+      size_t bytes_per_line = 2 * sizeof (struct line) - sizeof (struct line) / 2;
 
       if (! buf.alloc)
-       initbuf (&buf, 2 * sizeof (struct line),
+       initbuf (&buf, bytes_per_line,
                 sort_buffer_size (&fp, 1, files, nfiles,
-                                  2 * sizeof (struct line), size));
+                                  bytes_per_line, size));
       buf.eof = 0;
       files++;
       nfiles--;
@@ -2005,9 +2006,8 @@ sort (char **files, int nfiles, char const *output_file)
          struct line *linebase;
 
          if (buf.eof && nfiles
-             && (2 * sizeof (struct line) + 1
-                 < (buf.alloc - buf.used
-                    - 2 * sizeof (struct line) * buf.nlines)))
+             && (bytes_per_line + 1
+                 < (buf.alloc - buf.used - bytes_per_line * buf.nlines)))
            {
              /* End of file, but there is more input and buffer room.
                 Concatenate the next input file; this is faster in