diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2019-05-09 15:58:46 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2019-05-09 15:58:46 +0200 |
commit | 89023b167fad897fb6c0d2cdd24f0140beea7df3 (patch) | |
tree | 76a330b35745d7c67b59d6ea551272eb42ca9630 /miscutils | |
parent | 3106784e654e7443ab724d927f9de0230adbe5ac (diff) | |
download | busybox-w32-89023b167fad897fb6c0d2cdd24f0140beea7df3.tar.gz busybox-w32-89023b167fad897fb6c0d2cdd24f0140beea7df3.tar.bz2 busybox-w32-89023b167fad897fb6c0d2cdd24f0140beea7df3.zip |
dc: code shrink
function old new delta
check_under 20 21 +1
print_no_pop 32 27 -5
pop 24 18 -6
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/2 up/down: 1/-11) Total: -10 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'miscutils')
-rw-r--r-- | miscutils/dc.c | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/miscutils/dc.c b/miscutils/dc.c index 17fdda8fd..5119c1383 100644 --- a/miscutils/dc.c +++ b/miscutils/dc.c | |||
@@ -35,10 +35,12 @@ enum { STACK_SIZE = (COMMON_BUFSIZE - offsetof(struct globals, stack)) / sizeof( | |||
35 | base = 10; \ | 35 | base = 10; \ |
36 | } while (0) | 36 | } while (0) |
37 | 37 | ||
38 | static void check_under(void) | 38 | static unsigned check_under(void) |
39 | { | 39 | { |
40 | if (pointer == 0) | 40 | unsigned p = pointer; |
41 | if (p == 0) | ||
41 | bb_error_msg_and_die("stack underflow"); | 42 | bb_error_msg_and_die("stack underflow"); |
43 | return p - 1; | ||
42 | } | 44 | } |
43 | 45 | ||
44 | static void push(double a) | 46 | static void push(double a) |
@@ -50,8 +52,9 @@ static void push(double a) | |||
50 | 52 | ||
51 | static double pop(void) | 53 | static double pop(void) |
52 | { | 54 | { |
53 | check_under(); | 55 | unsigned p = check_under(); |
54 | return stack[--pointer]; | 56 | pointer = p; |
57 | return stack[p]; | ||
55 | } | 58 | } |
56 | 59 | ||
57 | static void add(void) | 60 | static void add(void) |
@@ -91,6 +94,14 @@ static void mod(void) | |||
91 | { | 94 | { |
92 | data_t d = pop(); | 95 | data_t d = pop(); |
93 | 96 | ||
97 | //if (d == 0) { | ||
98 | // bb_error_msg("remainder by zero"); | ||
99 | // pop(); | ||
100 | // push(0); | ||
101 | // return; | ||
102 | //} | ||
103 | //^^^^ without this, we simply get SIGFPE and die | ||
104 | |||
94 | push((data_t) pop() % d); | 105 | push((data_t) pop() % d); |
95 | } | 106 | } |
96 | 107 | ||
@@ -171,8 +182,7 @@ static void print_stack_no_pop(void) | |||
171 | 182 | ||
172 | static void print_no_pop(void) | 183 | static void print_no_pop(void) |
173 | { | 184 | { |
174 | check_under(); | 185 | print_base(stack[check_under()]); |
175 | print_base(stack[pointer-1]); | ||
176 | } | 186 | } |
177 | 187 | ||
178 | struct op { | 188 | struct op { |