Don't free the line buffer for each file

There's no point free-ing memory when the kernel can do it for us.
Just reuse the already allocated memory to hold lines.

Thanks Truls Becken for pointing this out.
This commit is contained in:
sin 2014-12-16 19:46:59 +00:00
parent a3e4689743
commit 0d7822f866

20
cut.c
View File

@ -74,18 +74,6 @@ parselist(char *str)
} }
} }
static void
freelist(void) {
Range *l = list, *next;
while (l) {
next = l->next;
free(l);
l->next = NULL;
l = next;
}
}
static size_t static size_t
seek(const char *s, size_t pos, size_t *prev, size_t count) seek(const char *s, size_t pos, size_t *prev, size_t count)
{ {
@ -116,8 +104,10 @@ seek(const char *s, size_t pos, size_t *prev, size_t count)
static void static void
cut(FILE *fp) cut(FILE *fp)
{ {
char *buf = NULL, *s; static char *buf = NULL;
size_t size = 0, i, n, p; static size_t size = 0;
char *s;
size_t i, n, p;
ssize_t len; ssize_t len;
Range *r; Range *r;
@ -143,7 +133,6 @@ cut(FILE *fp)
} }
putchar('\n'); putchar('\n');
} }
free(buf);
} }
int int
@ -190,6 +179,5 @@ main(int argc, char *argv[])
fclose(fp); fclose(fp);
} }
} }
freelist();
return 0; return 0;
} }