[PATCH] ash: reorder control characters to save bytes

Ron Yorston rmy at pobox.com
Fri Nov 16 13:18:03 UTC 2018


During the processing of argument strings ash uses non-ASCII values
to indicate particular constructs.  These values are arbitrary and
can be changed at will.

Sampling a number of permutations showed that the current choice
of values results in the largest code.  11% of samples were just
as bad and 89% were better.  The average reduction in code size
was 11.77 bytes.

function                                             old     new   delta
cmdputs                                              393     383     -10
argstr                                              1313    1301     -12
.rodata                                           168610  168594     -16
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/3 up/down: 0/-38)             Total: -38 bytes

Signed-off-by: Ron Yorston <rmy at pobox.com>
---
 shell/ash.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/shell/ash.c b/shell/ash.c
index 90eaf6faf..1f445dd41 100644
--- a/shell/ash.c
+++ b/shell/ash.c
@@ -715,15 +715,15 @@ out2str(const char *p)
 /* ============ Parser structures */
 
 /* control characters in argument strings */
-#define CTL_FIRST CTLESC
-#define CTLESC       ((unsigned char)'\201')    /* escape next character */
+#define CTL_FIRST CTLENDARI
+#define CTLENDARI    ((unsigned char)'\201')
 #define CTLVAR       ((unsigned char)'\202')    /* variable defn */
-#define CTLENDVAR    ((unsigned char)'\203')
-#define CTLBACKQ     ((unsigned char)'\204')
-#define CTLARI       ((unsigned char)'\206')    /* arithmetic expression */
-#define CTLENDARI    ((unsigned char)'\207')
-#define CTLQUOTEMARK ((unsigned char)'\210')
-#define CTL_LAST CTLQUOTEMARK
+#define CTLESC       ((unsigned char)'\203')    /* escape next character */
+#define CTLQUOTEMARK ((unsigned char)'\204')
+#define CTLENDVAR    ((unsigned char)'\205')
+#define CTLBACKQ     ((unsigned char)'\206')
+#define CTLARI       ((unsigned char)'\207')    /* arithmetic expression */
+#define CTL_LAST CTLARI
 
 /* variable substitution byte (follows CTLVAR) */
 #define VSTYPE  0x0f            /* type of variable substitution */
-- 
2.19.1



More information about the busybox mailing list