[PATCH] libbb print_flags() -380 bytes

Natanael Copa natanael.copa at gmail.com
Fri Jun 6 13:25:07 UTC 2008


On Fri, 2008-06-06 at 14:57 +0200, Denys Vlasenko wrote:
> Hi Natanael,
> 
> On Friday 06 June 2008 13:39, Natanael Copa wrote:
> > I have looked more at the print_flags() I started with yesterday.
> > 
> > Attatched are some patches and they should probably be committed to svn
> > separatly (easier to revert in case they have bugs).
> > 
> > I tried to use print_flags() in arp.c and fdisk.c but they seemed to
> > increase the size so I chosed to not included them here. (ping me if
> > someone want to take a look at them anyway)
> > 
> > Patches are rebased from svn trunk this morning.
> 
> Why it's "struct mask_string" in print_flags-libbb.patch
> but "struct flag_label" in other patches? something is wrong...

ouch... yes. I attatched wrong patch.

> But anyway.
> I bet the most of waste is in string pointer member here:
> 
> +struct mask_string {
> +       int mask;
> +       const char *string; <=====
> +};
...
> By changing
> 
> int print_flags(const struct mask_string *ms, int flags, const char *separator)
> 
> into
> 
> int print_flags(const int masks[], const char *strings, int flags, const char *separator)
> 
> and passing a vector of masks (0-terminated) and a single string,
> in the above example it would be
> "*\0""sdma0\0""*\0""sdma1\0""*\0""sdma2\0""*\0""sdma?",
> you will save ~30 bytes in that example alone.

thanks! i wanted something like that but could not find out how.

> Small note: you missed const at least here:
> 
> +                       static struct flag_label ultra_modes2[] = {
> 
> Overall, I welcome any patch which shrinks bbox. This one looks promising.

Got several good tips from Benhard too. Will have a look at it,
hopefully during the weekend.

thanks!

> --
> vda




More information about the busybox mailing list