From 33b35e255d1d045e28c4cd8c54c37808d0ed3ace Mon Sep 17 00:00:00 2001 From: Erich Eckner Date: Tue, 29 Nov 2016 10:58:34 +0100 Subject: sort: split off even more source lines useful for uniq --- src/sort-uniq-keyfuncs.c | 28 ++++++++++++++++++++++++++++ src/sort.c | 28 ---------------------------- 2 files changed, 28 insertions(+), 28 deletions(-) diff --git a/src/sort-uniq-keyfuncs.c b/src/sort-uniq-keyfuncs.c index d661aefe3..31bf03e19 100644 --- a/src/sort-uniq-keyfuncs.c +++ b/src/sort-uniq-keyfuncs.c @@ -174,6 +174,34 @@ sort_die (char const *message, char const *file) quotef (file ? file : _("standard output"))); } +/* Initialize BUF. Reserve LINE_BYTES bytes for each line; LINE_BYTES + must be at least sizeof (struct line). Allocate ALLOC bytes + initially. */ + +static void +initbuf (struct buffer *buf, size_t line_bytes, size_t alloc) +{ + /* Ensure that the line array is properly aligned. If the desired + size cannot be allocated, repeatedly halve it until allocation + succeeds. The smaller allocation may hurt overall performance, + but that's better than failing. */ + while (true) + { + alloc += sizeof (struct line) - alloc % sizeof (struct line); + buf->buf = malloc (alloc); + if (buf->buf) + break; + alloc /= 2; + if (alloc <= line_bytes + 1) + xalloc_die (); + } + + buf->line_bytes = line_bytes; + buf->alloc = alloc; + buf->used = buf->left = buf->nlines = 0; + buf->eof = false; +} + /* Return one past the limit of the line array. */ static inline struct line * diff --git a/src/sort.c b/src/sort.c index e2a3c7e3e..b7a6f7aec 100644 --- a/src/sort.c +++ b/src/sort.c @@ -1382,34 +1382,6 @@ sort_buffer_size (FILE *const *fps, size_t nfps, return size; } -/* Initialize BUF. Reserve LINE_BYTES bytes for each line; LINE_BYTES - must be at least sizeof (struct line). Allocate ALLOC bytes - initially. */ - -static void -initbuf (struct buffer *buf, size_t line_bytes, size_t alloc) -{ - /* Ensure that the line array is properly aligned. If the desired - size cannot be allocated, repeatedly halve it until allocation - succeeds. The smaller allocation may hurt overall performance, - but that's better than failing. */ - while (true) - { - alloc += sizeof (struct line) - alloc % sizeof (struct line); - buf->buf = malloc (alloc); - if (buf->buf) - break; - alloc /= 2; - if (alloc <= line_bytes + 1) - xalloc_die (); - } - - buf->line_bytes = line_bytes; - buf->alloc = alloc; - buf->used = buf->left = buf->nlines = 0; - buf->eof = false; -} - /* Initialize the randomly chosen MD5 state. */ static void -- cgit v1.2.3-54-g00ecf