[hackers] [sbase] Don't free the line buffer for each file || sin
commit 0d7822f8662747f2bb8a659469e39d545c388583
Author: sin <sin_AT_2f30.org>
Date: Tue Dec 16 19:46:59 2014 +0000
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.
diff --git a/cut.c b/cut.c
index 0206e47..aca0083 100644
--- a/cut.c
+++ b/cut.c
_AT_@ -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
seek(const char *s, size_t pos, size_t *prev, size_t count)
{
_AT_@ -116,8 +104,10 @@ seek(const char *s, size_t pos, size_t *prev, size_t count)
static void
cut(FILE *fp)
{
- char *buf = NULL, *s;
- size_t size = 0, i, n, p;
+ static char *buf = NULL;
+ static size_t size = 0;
+ char *s;
+ size_t i, n, p;
ssize_t len;
Range *r;
_AT_@ -143,7 +133,6 @@ cut(FILE *fp)
}
putchar('\n');
}
- free(buf);
}
int
_AT_@ -190,6 +179,5 @@ main(int argc, char *argv[])
fclose(fp);
}
}
- freelist();
return 0;
}
Received on Tue Dec 16 2014 - 20:49:50 CET
This archive was generated by hypermail 2.3.0
: Tue Dec 16 2014 - 21:00:10 CET