[git commit] bc: shrink bc_program_printString

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


commit: https://git.busybox.net/busybox/commit/?id=9f657e0f7deae5e27f95d783f52f897f42eafa57
branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master

function                                             old     new   delta
zbc_program_print                                    665     642     -23

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

diff --git a/miscutils/bc.c b/miscutils/bc.c
index be118d81d..5f1baf431 100644
--- a/miscutils/bc.c
+++ b/miscutils/bc.c
@@ -5585,87 +5585,55 @@ static char *bc_program_name(char *code, size_t *bgn)
 
 static void bc_program_printString(const char *str)
 {
-	size_t i, len = strlen(str);
-
 #if ENABLE_DC
-	if (len == 0) {
+	// Huh? Example when this happens?
+	if (!str[0]) {
 		bb_putchar('\0');
 		return;
 	}
 #endif
-
-	for (i = 0; i < len; ++i, ++G.prog.nchars) {
-
-		int c = str[i];
-
-		if (c != '\\' || i == len - 1)
+	while (*str) {
+		int c = *str++;
+		if (c != '\\' || !*str)
 			bb_putchar(c);
 		else {
-
-			c = str[++i];
-
+			c = *str++;
 			switch (c) {
-
-				case 'a':
-				{
-					bb_putchar('\a');
-					break;
-				}
-
-				case 'b':
-				{
-					bb_putchar('\b');
-					break;
-				}
-
-				case '\\':
-				case 'e':
-				{
-					bb_putchar('\\');
-					break;
-				}
-
-				case 'f':
-				{
-					bb_putchar('\f');
-					break;
-				}
-
-				case 'n':
-				{
-					bb_putchar('\n');
-					G.prog.nchars = SIZE_MAX;
-					break;
-				}
-
-				case 'r':
-				{
-					bb_putchar('\r');
-					break;
-				}
-
-				case 'q':
-				{
-					bb_putchar('"');
-					break;
-				}
-
-				case 't':
-				{
-					bb_putchar('\t');
-					break;
-				}
-
-				default:
-				{
-					// Just print the backslash and following character.
-					bb_putchar('\\');
-					++G.prog.nchars;
-					bb_putchar(c);
-					break;
-				}
+			case 'a':
+				bb_putchar('\a');
+				break;
+			case 'b':
+				bb_putchar('\b');
+				break;
+			case '\\':
+			case 'e':
+				bb_putchar('\\');
+				break;
+			case 'f':
+				bb_putchar('\f');
+				break;
+			case 'n':
+				bb_putchar('\n');
+				G.prog.nchars = SIZE_MAX;
+				break;
+			case 'r':
+				bb_putchar('\r');
+				break;
+			case 'q':
+				bb_putchar('"');
+				break;
+			case 't':
+				bb_putchar('\t');
+				break;
+			default:
+				// Just print the backslash and following character.
+				bb_putchar('\\');
+				++G.prog.nchars;
+				bb_putchar(c);
+				break;
 			}
 		}
+		++G.prog.nchars;
 	}
 }
 


More information about the busybox-cvs mailing list