[prev in list] [next in list] [prev in thread] [next in thread]
List: busybox
Subject: [PATCH 2/2] applet_tables: avoid duplication of applet names
From: Ron Yorston <rmy () pobox ! com>
Date: 2016-03-22 17:17:34
Message-ID: 56f17e2e.x+VCzXdxUTEEamQx%rmy () pobox ! com
[Download RAW message or body]
Modify the applet_tables utility so that, by suitably tweaking the name
offsets, applet names which appear as part of another name don't have to
be stored separately. Instead of:
const char applet_names[] ALIGN1 = ""
"[" "\0"
"[[" "\0"
const uint16_t applet_nameofs[] ALIGN2 = {
0x0000,
0x0002,
we get:
const char applet_names[] ALIGN1 = ""
"[[" "\0"
const uint16_t applet_nameofs[] ALIGN2 = {
0x0001,
0x0000,
The APPLET_NAME macro should be used to access applet names.
function old new delta
applet_names 2510 2332 -178
.rodata 155866 155688 -178
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-356) Total: -356 bytes
text data bss dec hex filename
823829 4078 9088 836995 cc583 busybox_old
823651 4078 9088 836817 cc4d1 busybox_unstripped
Signed-off-by: Ron Yorston <rmy@pobox.com>
---
applets/applet_tables.c | 58 ++++++++++++++++++++++++++++++++++++++++++++-----
1 file changed, 52 insertions(+), 6 deletions(-)
diff --git a/applets/applet_tables.c b/applets/applet_tables.c
index 92bf1e4..092a13b 100644
--- a/applets/applet_tables.c
+++ b/applets/applet_tables.c
@@ -42,6 +42,11 @@ struct bb_applet {
enum { NUM_APPLETS = ARRAY_SIZE(applets) };
static int offset[NUM_APPLETS];
+/*
+ * If subset[i] is non-negative applets.name[i] appears at the end
+ * of applets.name[subset[i]].
+ */
+static int subset[NUM_APPLETS];
static int cmp_name(const void *a, const void *b)
{
@@ -60,19 +65,58 @@ static int str_isalnum_(const char *s)
return 1;
}
+/* return 0 if s is longer than t and ends with t */
+static int end_match(const char *s, const char *t)
+{
+ int delta = strlen(s) - strlen(t);
+
+ if (delta <= 0)
+ return -1;
+
+ return strcmp(s+delta, t);
+}
+
int main(int argc, char **argv)
{
- int i;
+ int i, j;
int ofs;
// unsigned MAX_APPLET_NAME_LEN = 1;
qsort(applets, NUM_APPLETS, sizeof(applets[0]), cmp_name);
+ /* find which applet names are subsets of others */
+ for (i = 0; i < NUM_APPLETS; i++) {
+ subset[i] = -1;
+ for (j = 0; j < NUM_APPLETS; j++) {
+ if ( end_match(applets[j].name, applets[i].name) == 0 ) {
+ subset[i] = j;
+ break;
+ }
+ }
+ }
+
ofs = 0;
+ /* obtain offsets for names that will be output */
for (i = 0; i < NUM_APPLETS; i++) {
- offset[i] = ofs;
- ofs += strlen(applets[i].name) + 1;
+ if (subset[i] < 0) {
+ offset[i] = ofs;
+ ofs += strlen(applets[i].name) + 1;
+ }
}
+
+ /* obtain offsets for names that are contained in those output */
+ for (i = 0; i < NUM_APPLETS; i++) {
+ if (subset[i] >= 0) {
+ /* allow for indirection: sh -> ash -> fbsplash */
+ j = i;
+ while (subset[j] >= 0) {
+ j = subset[j];
+ }
+ offset[i] = offset[j] + strlen(applets[j].name) -
+ strlen(applets[i].name);
+ }
+ }
+
/* We reuse 4 high-order bits of offset array for other purposes,
* so if they are indeed needed, refuse to proceed */
if (ofs > 0xfff)
@@ -99,9 +143,11 @@ int main(int argc, char **argv)
//printf("#ifndef SKIP_definitions\n");
printf("const char applet_names[] ALIGN1 = \"\"\n");
for (i = 0; i < NUM_APPLETS; i++) {
- printf("\"%s\" \"\\0\"\n", applets[i].name);
-// if (MAX_APPLET_NAME_LEN < strlen(applets[i].name))
-// MAX_APPLET_NAME_LEN = strlen(applets[i].name);
+ if (subset[i] < 0) {
+ printf("\"%s\" \"\\0\"\n", applets[i].name);
+// if (MAX_APPLET_NAME_LEN < strlen(applets[i].name))
+// MAX_APPLET_NAME_LEN = strlen(applets[i].name);
+ }
}
printf(";\n\n");
--
2.5.5
_______________________________________________
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic