mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH] some small binary size improvement patches
@ 2012-06-28 10:48 Sascha Hauer
  2012-06-28 10:48 ` [PATCH 1/3] menu: factor out a function to print an entry Sascha Hauer
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Sascha Hauer @ 2012-06-28 10:48 UTC (permalink / raw)
  To: barebox

Not much, but at least a few hundred bytes.

Sascha

----------------------------------------------------------------
Sascha Hauer (3):
      menu: factor out a function to print an entry
      net: Use dev_name directly
      dos partitions: enable disk size guessing only for bios disks

 common/menu.c       |   70 +++++++++++----------------------------------------
 common/partitions.c |    2 +-
 include/menu.h      |    3 ---
 net/eth.c           |    4 +--
 4 files changed, 17 insertions(+), 62 deletions(-)

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 1/3] menu: factor out a function to print an entry
  2012-06-28 10:48 [PATCH] some small binary size improvement patches Sascha Hauer
@ 2012-06-28 10:48 ` Sascha Hauer
  2012-06-28 10:48 ` [PATCH 2/3] net: Use dev_name directly Sascha Hauer
  2012-06-28 10:48 ` [PATCH 3/3] dos partitions: enable disk size guessing only for bios disks Sascha Hauer
  2 siblings, 0 replies; 4+ messages in thread
From: Sascha Hauer @ 2012-06-28 10:48 UTC (permalink / raw)
  To: barebox

To save a few bytes of binary space.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 common/menu.c  |   70 ++++++++++++--------------------------------------------
 include/menu.h |    3 ---
 2 files changed, 15 insertions(+), 58 deletions(-)

diff --git a/common/menu.c b/common/menu.c
index 6c530b6..649926f 100644
--- a/common/menu.c
+++ b/common/menu.c
@@ -53,7 +53,6 @@ void menu_free(struct menu *m)
 	free(m->name);
 	free(m->display);
 	free(m->auto_display);
-	free(m->display_buffer);
 
 	list_for_each_entry_safe(me, tmp, &m->entries, list)
 		menu_entry_free(me);
@@ -87,15 +86,9 @@ EXPORT_SYMBOL(menu_remove);
 
 int menu_add_entry(struct menu *m, struct menu_entry *me)
 {
-	int len;
-
 	if (!m || !me || !me->display)
 		return -EINVAL;
 
-	len = strlen(me->display);
-
-	m->width = max(len, m->width);
-
 	m->nb_entries++;
 	me->num = m->nb_entries;
 	list_add_tail(&me->list, &m->entries);
@@ -160,6 +153,18 @@ void menu_entry_free(struct menu_entry *me)
 }
 EXPORT_SYMBOL(menu_entry_free);
 
+static void __print_entry(const char *str)
+{
+	static char outstr[256];
+
+	if (IS_ENABLED(CONFIG_SHELL_HUSH)) {
+		process_escape_sequence(str, outstr, 256);
+		puts(outstr);
+	} else {
+		puts(str);
+	}
+}
+
 static void print_menu_entry(struct menu *m, struct menu_entry *me,
 			     int selected)
 {
@@ -174,17 +179,11 @@ static void print_menu_entry(struct menu *m, struct menu_entry *me,
 		puts("   ");
 	}
 
-	if (IS_ENABLED(CONFIG_SHELL_HUSH))
-		process_escape_sequence(me->display, m->display_buffer,
-					m->display_buffer_size);
-
 	printf(" %d: ", me->num);
 	if (selected)
 		puts("\e[7m");
-	if (IS_ENABLED(CONFIG_SHELL_HUSH))
-		puts(m->display_buffer);
-	else
-		puts(me->display);
+
+	__print_entry(me->display);
 
 	if (selected)
 		puts("\e[m");
@@ -241,13 +240,7 @@ static void print_menu(struct menu *m)
 	clear();
 	gotoXY(1, 2);
 	if(m->display) {
-		if (IS_ENABLED(CONFIG_SHELL_HUSH)) {
-			process_escape_sequence(m->display, m->display_buffer,
-						m->display_buffer_size);
-			puts(m->display_buffer);
-		} else {
-			puts(m->display);
-		}
+		__print_entry(m->display);
 	} else {
 		puts("Menu : ");
 		puts(m->name);
@@ -266,34 +259,6 @@ static void print_menu(struct menu *m)
 	print_menu_entry(m, m->selected, 1);
 }
 
-static int menu_alloc_display_buffer(struct menu *m)
-{
-	int min_size;
-
-	if (m->display)
-		min_size = max((int)strlen(m->display), m->width);
-	else
-		min_size = m->width;
-
-
-	if (m->display_buffer) {
-		if (m->display_buffer_size >= min_size)
-			return 0;
-		m->display_buffer = realloc(m->display_buffer, min_size * sizeof(char));
-	} else {
-		m->display_buffer = calloc(min_size, sizeof(char));
-	}
-
-	if (!m->display_buffer) {
-		perror("display_buffer");
-		return -ENOMEM;
-	}
-
-	m->display_buffer_size = min_size;
-
-	return 0;
-}
-
 int menu_show(struct menu *m)
 {
 	int ch, ch_previous = 0;
@@ -301,15 +266,10 @@ int menu_show(struct menu *m)
 	int countdown;
 	int auto_display_len = 16;
 	uint64_t start, second;
-	int ret;
 
 	if(!m || list_empty(&m->entries))
 		return -EINVAL;
 
-	ret = menu_alloc_display_buffer(m);
-	if (ret)
-		return ret;
-
 	print_menu(m);
 
 	countdown = m->auto_select;
diff --git a/include/menu.h b/include/menu.h
index 74abcfb..40f8eab 100644
--- a/include/menu.h
+++ b/include/menu.h
@@ -60,9 +60,6 @@ struct menu {
 	struct list_head entries;
 
 	int nb_entries;
-	int width;
-	char *display_buffer;
-	int display_buffer_size;
 
 	struct menu_entry *selected;
 	void *priv;
-- 
1.7.10


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 2/3] net: Use dev_name directly
  2012-06-28 10:48 [PATCH] some small binary size improvement patches Sascha Hauer
  2012-06-28 10:48 ` [PATCH 1/3] menu: factor out a function to print an entry Sascha Hauer
@ 2012-06-28 10:48 ` Sascha Hauer
  2012-06-28 10:48 ` [PATCH 3/3] dos partitions: enable disk size guessing only for bios disks Sascha Hauer
  2 siblings, 0 replies; 4+ messages in thread
From: Sascha Hauer @ 2012-06-28 10:48 UTC (permalink / raw)
  To: barebox

eth_get_byname uses a selfmade dev_name, use dev_name directly instead.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 net/eth.c |    4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/net/eth.c b/net/eth.c
index 2b492ad..e023d65 100644
--- a/net/eth.c
+++ b/net/eth.c
@@ -100,11 +100,9 @@ struct eth_device * eth_get_current(void)
 struct eth_device *eth_get_byname(char *ethname)
 {
 	struct eth_device *edev;
-	char name[MAX_DRIVER_NAME];
 
 	list_for_each_entry(edev, &netdev_list, list) {
-		sprintf(name, "%s%d", edev->dev.name, edev->dev.id);
-		if (!strcmp(ethname, name))
+		if (!strcmp(ethname, dev_name(&edev->dev)))
 			return edev;
 	}
 	return NULL;
-- 
1.7.10


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 3/3] dos partitions: enable disk size guessing only for bios disks
  2012-06-28 10:48 [PATCH] some small binary size improvement patches Sascha Hauer
  2012-06-28 10:48 ` [PATCH 1/3] menu: factor out a function to print an entry Sascha Hauer
  2012-06-28 10:48 ` [PATCH 2/3] net: Use dev_name directly Sascha Hauer
@ 2012-06-28 10:48 ` Sascha Hauer
  2 siblings, 0 replies; 4+ messages in thread
From: Sascha Hauer @ 2012-06-28 10:48 UTC (permalink / raw)
  To: barebox

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 common/partitions.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/common/partitions.c b/common/partitions.c
index 74b4f12..c5bce6e 100644
--- a/common/partitions.c
+++ b/common/partitions.c
@@ -119,7 +119,7 @@ static void __maybe_unused try_dos_partition(struct block_device *blk,
 	table = (struct partition_entry *)&buffer[446];
 
 	/* valid for x86 BIOS based disks only */
-	if (blk->num_blocks == 0)
+	if (IS_ENABLED(CONFIG_DISK_BIOS) && blk->num_blocks == 0)
 		blk->num_blocks = disk_guess_size(blk->dev, table);
 
 	for (i = 0; i < 4; i++) {
-- 
1.7.10


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2012-06-28 10:48 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-06-28 10:48 [PATCH] some small binary size improvement patches Sascha Hauer
2012-06-28 10:48 ` [PATCH 1/3] menu: factor out a function to print an entry Sascha Hauer
2012-06-28 10:48 ` [PATCH 2/3] net: Use dev_name directly Sascha Hauer
2012-06-28 10:48 ` [PATCH 3/3] dos partitions: enable disk size guessing only for bios disks Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox