summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>2000-03-06 06:20:59 +0000
committerJim Meyering <jim@meyering.net>2000-03-06 06:20:59 +0000
commit57bb2e656e63c2335767086083e882997e0043ab (patch)
treeab40b5531baad16352206b2ad03b155c4c5da30e /src
parent12ad88f5c1d05ba0cbb8dafbdf698248952cb9f8 (diff)
downloadcoreutils-57bb2e656e63c2335767086083e882997e0043ab.tar.xz
(struct buffer.newline_free): New member.
(initbuf, findlines): Set it. (fillbuf): Do not double the size of a full buffer to append a newline unless the buffer is known to be newline free.
Diffstat (limited to 'src')
-rw-r--r--src/sort.c13
1 files changed, 10 insertions, 3 deletions
diff --git a/src/sort.c b/src/sort.c
index 2b064db57..acd564202 100644
--- a/src/sort.c
+++ b/src/sort.c
@@ -127,7 +127,9 @@ struct buffer
char *buf; /* Dynamically allocated buffer. */
int used; /* Number of bytes used. */
int alloc; /* Number of bytes allocated. */
- int left; /* Number of bytes left after line parsing. */
+ int left; /* Number of bytes left from previous reads. */
+ int newline_free; /* Number of left bytes that are known
+ to be newline-free. */
};
struct keyfield
@@ -534,7 +536,7 @@ initbuf (struct buffer *buf, int alloc)
{
buf->alloc = alloc;
buf->buf = xmalloc (buf->alloc);
- buf->used = buf->left = 0;
+ buf->used = buf->left = buf->newline_free = 0;
}
/* Fill BUF reading from FP, moving buf->left bytes from the end
@@ -575,6 +577,11 @@ fillbuf (struct buffer *buf, FILE *fp)
{
if (buf->used == buf->alloc)
{
+ /* If the buffer isn't parsed yet, don't increase the buffer
+ size to append a newline, as this won't be needed unless
+ the buffer turns out to be newline-free. */
+ if (buf->newline_free != buf->used)
+ return buf->used;
buf->alloc *= 2;
buf->buf = xrealloc (buf->buf, buf->alloc);
}
@@ -795,7 +802,7 @@ findlines (struct buffer *buf, struct lines *lines)
beg = ptr + 1;
}
- buf->left = lim - beg;
+ buf->newline_free = buf->left = lim - beg;
}
/* Compare strings A and B containing decimal fractions < 1. Each string