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...
But anyway.
I bet the most of waste is in string pointer member here:
+struct mask_string {
+ int mask;
+ const char *string; <=====
+};
Just count how many of char* pointers are here:
+ static const struct flag_label dma_1word_modes[] = {
+ { 0x100, "*" },
+ { 1, "sdma0" },
+ { 0x200, "*" },
+ { 2, "sdma1" },
+ { 0x400, "*" },
+ { 4, "sdma2" },
+ { 0xf800, "*" },
+ { 0xf8, "sdma?" },
+ { 0, NULL },
+ };
Nine! Each ptr is 4 or even 8 bytes.
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.
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.
--
vda
_______________________________________________
busybox mailing list
[email protected]
http://busybox.net/cgi-bin/mailman/listinfo/busybox