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>
This commit is contained in:
parent
3106784e65
commit
89023b167f
@ -35,10 +35,12 @@ enum { STACK_SIZE = (COMMON_BUFSIZE - offsetof(struct globals, stack)) / sizeof(
|
|||||||
base = 10; \
|
base = 10; \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
static void check_under(void)
|
static unsigned check_under(void)
|
||||||
{
|
{
|
||||||
if (pointer == 0)
|
unsigned p = pointer;
|
||||||
|
if (p == 0)
|
||||||
bb_error_msg_and_die("stack underflow");
|
bb_error_msg_and_die("stack underflow");
|
||||||
|
return p - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void push(double a)
|
static void push(double a)
|
||||||
@ -50,8 +52,9 @@ static void push(double a)
|
|||||||
|
|
||||||
static double pop(void)
|
static double pop(void)
|
||||||
{
|
{
|
||||||
check_under();
|
unsigned p = check_under();
|
||||||
return stack[--pointer];
|
pointer = p;
|
||||||
|
return stack[p];
|
||||||
}
|
}
|
||||||
|
|
||||||
static void add(void)
|
static void add(void)
|
||||||
@ -91,6 +94,14 @@ static void mod(void)
|
|||||||
{
|
{
|
||||||
data_t d = pop();
|
data_t d = pop();
|
||||||
|
|
||||||
|
//if (d == 0) {
|
||||||
|
// bb_error_msg("remainder by zero");
|
||||||
|
// pop();
|
||||||
|
// push(0);
|
||||||
|
// return;
|
||||||
|
//}
|
||||||
|
//^^^^ without this, we simply get SIGFPE and die
|
||||||
|
|
||||||
push((data_t) pop() % d);
|
push((data_t) pop() % d);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -171,8 +182,7 @@ static void print_stack_no_pop(void)
|
|||||||
|
|
||||||
static void print_no_pop(void)
|
static void print_no_pop(void)
|
||||||
{
|
{
|
||||||
check_under();
|
print_base(stack[check_under()]);
|
||||||
print_base(stack[pointer-1]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct op {
|
struct op {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user