[PATCH] Compress common substrings in applet names to save space
Ron Yorston
rmy at pobox.com
Wed Apr 20 12:54:08 UTC 2016
Denys Vlasenko wrote:
>How about this version?
Neat. The generated include file is much prettier and you managed to
squeeze out a few more bytes.
A couple of things:
Since you've dropped the adjustment to the number of offsets you can
remove 2*KNOWN_APPNAME_OFFSETS from the size calculation;
hex_char() should really be called octal_char();
and it has a whitespace issue. (Sorry, that's three things.)
>However, I also think that this idea is slightly too insane...
Aww. :-(
Most of the complexity is at build-time, in the generation of the applet
tables. I'm actually quite pleased with how the run-time code turned out.
Ron
---
applets/applet_tables.c | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/applets/applet_tables.c b/applets/applet_tables.c
index 69d451a..af9a658 100644
--- a/applets/applet_tables.c
+++ b/applets/applet_tables.c
@@ -86,14 +86,14 @@ struct bb_substr {
static int numsub = 0;
static struct bb_substr substr[128];
-static char *hex_char(unsigned char c)
+static char *octal_char(unsigned char c)
{
static char expand[8][8];
static unsigned index = 0;
char *t;
t = expand[index];
- index = (index + 1) % 8;
+ index = (index + 1) % 8;
t[0] = c;
t[1] = '\0';
@@ -277,7 +277,7 @@ int main(int argc, char **argv)
}
/* only use substrings if the saving outweighs the larger code */
- newtot = newlen + (numsub*SUBLEN) + 160 + 2*KNOWN_APPNAME_OFFSETS;
+ newtot = newlen + (numsub*SUBLEN) + 160;
ABBREV_APPLET_NAMES = (newtot < oldlen);
if (ABBREV_APPLET_NAMES) {
@@ -295,13 +295,13 @@ int main(int argc, char **argv)
printf("static const char applet_common[][2] ALIGN1 = {\n");
for (n = 0; n < numsub; n++) {
printf("/* %s %2u %-8s */",
- hex_char(n + 0x80),
+ octal_char(n + 0x80),
substr[n].count,
expand_name(substr[n].str)
);
printf(" {'%s','%s'},\n",
- hex_char(substr[n].str[0]),
- hex_char(substr[n].str[1])
+ octal_char(substr[n].str[0]),
+ octal_char(substr[n].str[1])
);
}
printf("};\n\n");
@@ -314,7 +314,7 @@ int main(int argc, char **argv)
expand_name(applets[i].abbrev)
);
for (s = applets[i].abbrev; *s; s++) {
- printf("%s", hex_char(*s));
+ printf("%s", octal_char(*s));
}
printf("\" \"\\0\"\n");
}
--
2.5.5
More information about the busybox
mailing list