diff options
author | Marc Espie <espie@cvs.openbsd.org> | 2000-02-02 14:00:13 +0000 |
---|---|---|
committer | Marc Espie <espie@cvs.openbsd.org> | 2000-02-02 14:00:13 +0000 |
commit | 372a42b6982432777592e67c66529a075b44ae0b (patch) | |
tree | 7093d64a38c3ae091fae83cb6d4746105a96914b /usr.bin | |
parent | 89cfbc73b83ac826bd95ad3336d0d9d7cee0d517 (diff) |
Optimize common case.
outputstr could be called for one character-long string.
Looking at profiling output, it WAS called for one-character long strings
most of the time, like 95% of calls...
Rework logic slightly to know about that case and output the character
directly.
Worth about 10%.
Reviewed by Paul Janzen.
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/m4/main.c | 29 |
1 files changed, 14 insertions, 15 deletions
diff --git a/usr.bin/m4/main.c b/usr.bin/m4/main.c index 309b32e4748..786e2a7e930 100644 --- a/usr.bin/m4/main.c +++ b/usr.bin/m4/main.c @@ -1,4 +1,4 @@ -/* $OpenBSD: main.c,v 1.28 2000/01/15 14:26:00 espie Exp $ */ +/* $OpenBSD: main.c,v 1.29 2000/02/02 14:00:12 espie Exp $ */ /* $NetBSD: main.c,v 1.12 1997/02/08 23:54:49 cgd Exp $ */ /*- @@ -47,7 +47,7 @@ static char copyright[] = #if 0 static char sccsid[] = "@(#)main.c 8.1 (Berkeley) 6/6/93"; #else -static char rcsid[] = "$OpenBSD: main.c,v 1.28 2000/01/15 14:26:00 espie Exp $"; +static char rcsid[] = "$OpenBSD: main.c,v 1.29 2000/02/02 14:00:12 espie Exp $"; #endif #endif /* not lint */ @@ -273,8 +273,7 @@ do_look_ahead(t, token) static void macro() { - char token[MAXTOK], chars[2]; - char *s; + char token[MAXTOK]; int t, l; ndptr p; int nlpar; @@ -282,13 +281,12 @@ macro() cycle { t = gpbc(); if (t == '_' || isalpha(t)) { - s = token; - p = inspect(t, s); + p = inspect(t, token); if (p != nil) putback(l = gpbc()); if (p == nil || (l != LPAREN && (p->type & NEEDARGS) != 0)) - outputstr(s); + outputstr(token); else { /* * real thing.. First build a call frame: @@ -333,11 +331,11 @@ macro() l = gpbc(); if (LOOK_AHEAD(l,rquote)) { - nlpar--; - s = rquote; + if (--nlpar > 0) + outputstr(rquote); } else if (LOOK_AHEAD(l,lquote)) { record(quotes, nlpar++); - s = lquote; + outputstr(lquote); } else if (l == EOF) { if (nlpar == 1) warnx("unclosed quote:"); @@ -346,12 +344,13 @@ macro() dump_stack(quotes, nlpar); exit(1); } else { - chars[0] = l; - chars[1] = EOS; - s = chars; + if (nlpar > 0) { + if (sp < 0) + putc(l, active); + else + chrsave(l); + } } - if (nlpar > 0) - outputstr(s); } while (nlpar != 0); } |