[git commit] bc: code shrink

Denys Vlasenko vda.linux at googlemail.com
Tue Dec 18 18:17:11 UTC 2018


commit: https://git.busybox.net/busybox/commit/?id=694d2982e5cc73edfc870e26647e85a558d71bbe
branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master

function                                             old     new   delta
bc_program_name                                       67      63      -4
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-4)               Total: -4 bytes
   text	   data	    bss	    dec	    hex	filename
 981372	    485	   7296	 989153	  f17e1	busybox_old
 981368	    485	   7296	 989149	  f17dd	busybox_unstripped

Signed-off-by: Denys Vlasenko <vda.linux at googlemail.com>
---
 miscutils/bc.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/miscutils/bc.c b/miscutils/bc.c
index 40bb29942..eba8aa272 100644
--- a/miscutils/bc.c
+++ b/miscutils/bc.c
@@ -5174,17 +5174,19 @@ static size_t bc_program_index(char *code, size_t *bgn)
 static char *bc_program_name(char *code, size_t *bgn)
 {
 	size_t i;
-	char *s, *str = code + *bgn, *ptr = strchr(str, BC_PARSE_STREND);
+	char *s;
 
-	s = xmalloc(ptr - str + 1);
+	code += *bgn;
+	s = xmalloc(strchr(code, BC_PARSE_STREND) - code + 1);
 	i = 0;
 	for (;;) {
-		char c = code[(*bgn)++];
-		if (c == '\0' || c == BC_PARSE_STREND)
+		char c = *code++;
+		if (c == BC_PARSE_STREND)
 			break;
 		s[i++] = c;
 	}
 	s[i] = '\0';
+	*bgn += i + 1;
 
 	return s;
 }


More information about the busybox-cvs mailing list