improved last
Denys Vlasenko
vda.linux at googlemail.com
Wed May 21 23:13:18 UTC 2008
On Wednesday 21 May 2008 19:44, Denys Vlasenko wrote:
> > > Can you work on it a bit more?
> > >
> > > static int boot_down = 0;
> > >
> > > Completely wasted four bytes. grep for it.
> >
> > Alright, I did that and managed to save 2 bytes. I also tested to
> > remove most of the other static variables. That led to increased
> > size. If you think the 2 bytes lighter version of the applet is
> > interesting, just let me know.
>
> This is a 10-minute worth of shrinking:
>
> function old new delta
> show_entry 355 359 +4
> boot_down 4 1 -3
> show_wide 4 - -4
> filename 4 - -4
> last_main 1084 1030 -54
> ------------------------------------------------------------------------------
> (add/remove: 0/2 grow/shrink: 1/2 up/down: 4/-65) Total: -61 bytes
>
> # size last-org.o last.o
> text data bss dec hex filename
> 1730 12 24 1766 6e6 last-org.o
> 1680 8 17 1705 6a9 last.o
And this one is even smaller:
# ./.cmklog bloatcheck
function old new delta
show_entry 355 359 +4
start_time 4 - -4
show_wide 4 - -4
list 388 384 -4
filename 4 - -4
boot_down 4 - -4
static.ret 8 - -8
static.pos 8 - -8
last_main 1084 1058 -26
add_entry 45 - -45
------------------------------------------------------------------------------
(add/remove: 0/7 grow/shrink: 1/2 up/down: 4/-107) Total: -103 bytes
In particular, it doesn't have any data/bss:
# size last-org.o last.o
text data bss dec hex filename
1730 12 24 1766 6e6 last-org.o
1663 0 0 1663 67f last.o
One bug fixed. Old code was:
lseek(file, -(off_t)sizeof(struct utmp), SEEK_END);
for (;;) {
if (read_entry(file, &ut) != sizeof(struct utmp)) {
break;
}
static int read_entry(int file, struct utmp *ut)
{
...
n = full_read(file, ut, sizeof(struct utmp));
Imagine what will happen if the file is empty...
I changed the logic so that it handles that case.
However, if the file's size is not a multiple of sizeof(struct utmp),
both old and current code will be totally confused.
Unknown number of bugs added...
--
vda
-------------- next part --------------
A non-text attachment was scrubbed...
Name: last_fancy.c
Type: text/x-csrc
Size: 6323 bytes
Desc: not available
Url : http://lists.busybox.net/pipermail/busybox/attachments/20080522/7a275cf0/attachment-0002.c
More information about the busybox
mailing list