aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2010-03-12 21:32:13 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2010-03-12 21:32:13 +0100
commitf9782ffc451a99fcd7ab54b05500dbf94e687066 (patch)
treee54a6604b9c1f093b710843d151755c80576a709
parentc6ba9979782309491d7922f8ad205469e6549303 (diff)
downloadbusybox-w32-f9782ffc451a99fcd7ab54b05500dbf94e687066.tar.gz
busybox-w32-f9782ffc451a99fcd7ab54b05500dbf94e687066.tar.bz2
busybox-w32-f9782ffc451a99fcd7ab54b05500dbf94e687066.zip
awk: code shrink
function old new delta evaluate 3550 3487 -63 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--editors/awk.c72
1 files changed, 39 insertions, 33 deletions
diff --git a/editors/awk.c b/editors/awk.c
index c8e78a16c..30c6b88ef 100644
--- a/editors/awk.c
+++ b/editors/awk.c
@@ -2302,19 +2302,7 @@ static var *evaluate(node *op, var *res)
2302#define seed (G.evaluate__seed) 2302#define seed (G.evaluate__seed)
2303#define sreg (G.evaluate__sreg) 2303#define sreg (G.evaluate__sreg)
2304 2304
2305 node *op1;
2306 var *v1; 2305 var *v1;
2307 struct {
2308 var *v;
2309 const char *s;
2310 } L = L; /* for compiler */
2311 struct {
2312 var *v;
2313 const char *s;
2314 } R = R;
2315 double L_d = L_d;
2316 uint32_t opinfo;
2317 int opn;
2318 2306
2319 if (!op) 2307 if (!op)
2320 return setvar_s(res, NULL); 2308 return setvar_s(res, NULL);
@@ -2322,12 +2310,25 @@ static var *evaluate(node *op, var *res)
2322 v1 = nvalloc(2); 2310 v1 = nvalloc(2);
2323 2311
2324 while (op) { 2312 while (op) {
2313 struct {
2314 var *v;
2315 const char *s;
2316 } L = L; /* for compiler */
2317 struct {
2318 var *v;
2319 const char *s;
2320 } R = R;
2321 double L_d = L_d;
2322 uint32_t opinfo;
2323 int opn;
2324 node *op1;
2325
2325 opinfo = op->info; 2326 opinfo = op->info;
2326 opn = (opinfo & OPNMASK); 2327 opn = (opinfo & OPNMASK);
2327 g_lineno = op->lineno; 2328 g_lineno = op->lineno;
2329 op1 = op->l.n;
2328 2330
2329 /* execute inevitable things */ 2331 /* execute inevitable things */
2330 op1 = op->l.n;
2331 if (opinfo & OF_RES1) 2332 if (opinfo & OF_RES1)
2332 L.v = evaluate(op1, v1); 2333 L.v = evaluate(op1, v1);
2333 if (opinfo & OF_RES2) 2334 if (opinfo & OF_RES2)
@@ -2429,20 +2430,23 @@ static var *evaluate(node *op, var *res)
2429 2430
2430 case XC( OC_DELETE ): { 2431 case XC( OC_DELETE ): {
2431 uint32_t info = op1->info & OPCLSMASK; 2432 uint32_t info = op1->info & OPCLSMASK;
2433 var *v;
2434
2432 if (info == OC_VAR) { 2435 if (info == OC_VAR) {
2433 R.v = op1->l.v; 2436 v = op1->l.v;
2434 } else if (info == OC_FNARG) { 2437 } else if (info == OC_FNARG) {
2435 R.v = &fnargs[op1->l.aidx]; 2438 v = &fnargs[op1->l.aidx];
2436 } else { 2439 } else {
2437 syntax_error(EMSG_NOT_ARRAY); 2440 syntax_error(EMSG_NOT_ARRAY);
2438 } 2441 }
2439 2442
2440 if (op1->r.n) { 2443 if (op1->r.n) {
2444 const char *s;
2441 clrvar(L.v); 2445 clrvar(L.v);
2442 L.s = getvar_s(evaluate(op1->r.n, v1)); 2446 s = getvar_s(evaluate(op1->r.n, v1));
2443 hash_remove(iamarray(R.v), L.s); 2447 hash_remove(iamarray(v), s);
2444 } else { 2448 } else {
2445 clear_array(iamarray(R.v)); 2449 clear_array(iamarray(v));
2446 } 2450 }
2447 break; 2451 break;
2448 } 2452 }
@@ -2520,30 +2524,32 @@ static var *evaluate(node *op, var *res)
2520 break; 2524 break;
2521 2525
2522 case XC( OC_FUNC ): { 2526 case XC( OC_FUNC ): {
2523 var *v; 2527 var *vbeg, *v;
2528 const char *sv_progname;
2524 2529
2525 if (!op->r.f->body.first) 2530 if (!op->r.f->body.first)
2526 syntax_error(EMSG_UNDEF_FUNC); 2531 syntax_error(EMSG_UNDEF_FUNC);
2527 2532
2528 v = R.v = nvalloc(op->r.f->nargs + 1); 2533 vbeg = v = nvalloc(op->r.f->nargs + 1);
2529 while (op1) { 2534 while (op1) {
2530 L.v = evaluate(nextarg(&op1), v1); 2535 var *arg = evaluate(nextarg(&op1), v1);
2531 copyvar(R.v, L.v); 2536 copyvar(v, arg);
2532 R.v->type |= VF_CHILD; 2537 v->type |= VF_CHILD;
2533 R.v->x.parent = L.v; 2538 v->x.parent = arg;
2534 if (++R.v - v >= op->r.f->nargs) 2539 if (++v - vbeg >= op->r.f->nargs)
2535 break; 2540 break;
2536 } 2541 }
2537 2542
2538 R.v = fnargs; 2543 v = fnargs;
2539 fnargs = v; 2544 fnargs = vbeg;
2545 sv_progname = g_progname;
2540 2546
2541 L.s = g_progname;
2542 res = evaluate(op->r.f->body.first, res); 2547 res = evaluate(op->r.f->body.first, res);
2543 g_progname = L.s;
2544 2548
2549 g_progname = sv_progname;
2545 nvfree(fnargs); 2550 nvfree(fnargs);
2546 fnargs = R.v; 2551 fnargs = v;
2552
2547 break; 2553 break;
2548 } 2554 }
2549 2555
@@ -2790,9 +2796,9 @@ static var *evaluate(node *op, var *res)
2790 if (is_numeric(L.v) && is_numeric(R.v)) { 2796 if (is_numeric(L.v) && is_numeric(R.v)) {
2791 Ld = getvar_i(L.v) - getvar_i(R.v); 2797 Ld = getvar_i(L.v) - getvar_i(R.v);
2792 } else { 2798 } else {
2793 L.s = getvar_s(L.v); 2799 const char *l = getvar_s(L.v);
2794 R.s = getvar_s(R.v); 2800 const char *r = getvar_s(R.v);
2795 Ld = icase ? strcasecmp(L.s, R.s) : strcmp(L.s, R.s); 2801 Ld = icase ? strcasecmp(l, r) : strcmp(l, r);
2796 } 2802 }
2797 switch (opn & 0xfe) { 2803 switch (opn & 0xfe) {
2798 case 0: 2804 case 0: