On Thu, 2008-01-10 at 09:01 +0100, Tito wrote:
> Hi Denis,
> couldn't we change this 0x7f
>
> if (!(i & 0x7f))
> /* Grow on every 128th char */
> line = xrealloc(line, i + 0x7f + sizeof(int) + 1);
>
> into a define
>
> #define WHATEVER 0x7f
>
> so that it could be changed in one place
> and to improve readability for newbies like me. :-)
>
> Just an idea.
see attatched patch
but im not sure if it makes code more readable
>
> Ciao,
> Tito
Index: coreutils/tac.c
===================================================================
--- coreutils/tac.c (revision 20841)
+++ coreutils/tac.c (working copy)
@@ -20,6 +20,9 @@
/* This is a NOEXEC applet. Be very careful! */
+#define GROW_SIZE 128 /* must be a multiple by 2 */
+#define GROW_SIZE_BITMASK (GROW_SIZE - 1)
+
struct lstring {
int size;
char buf[];
@@ -56,9 +59,9 @@
do {
ch = fgetc(f);
if (ch != EOF) {
- if (!(i & 0x7f))
- /* Grow on every 128th char */
- line = xrealloc(line, i + 0x7f + sizeof(int) + 1);
+ if (!(i & GROW_SIZE_BITMASK))
+ /* Grow on every Nth char */
+ line = xrealloc(line, i + GROW_SIZE + sizeof(int));
line->buf[i++] = ch;
}
if ((ch == '\n' || ch == EOF) && i) {
_______________________________________________
busybox mailing list
[email protected]
http://busybox.net/cgi-bin/mailman/listinfo/busybox