[rfc] slight optimization to prevent memory thrashing in file reading
Mike Frysinger
vapier at gentoo.org
Wed Apr 11 15:47:36 PDT 2007
in rev 16374, bb_get_chunk_from_file() was tweaked by adding another call to
realloc() in case the buffer happened to be filled up completely ... however,
this is done unconditionally which often leads to an extra realloc() call
(whenever a line is not a multiple of 80 characters). this managed to expose
a bug in uClibc's simple realloc() when the new size requested is actually
smaller than the old size (people rarely use realloc() to *shrink* buffers,
they use it to *expand* buffers). regardless, i'd propose this simple
change:
+if (!((idx+1) % 80))
linebuf = xrealloc(linebuf, idx+1);
quick link for peeps:
http://busybox.net/cgi-bin/viewcvs.cgi?view=rev&rev=16374
-mike
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 827 bytes
Desc: not available
Url : http://busybox.net/lists/busybox/attachments/20070411/0f146d19/attachment-0001.pgp
More information about the busybox
mailing list