diff options
author | 2000-02-02 14:00:12 +0000 | |
---|---|---|
committer | 2000-02-02 14:00:12 +0000 | |
commit | b1125354bbf6daff88130e1698097b005b8d244e (patch) | |
tree | fd63dc9eaa611b2ca96df606443daf65fd393aad | |
parent | Bug-fix: make should behave sensibly when presented with negative times... (diff) | |
download | wireguard-openbsd-b1125354bbf6daff88130e1698097b005b8d244e.tar.xz wireguard-openbsd-b1125354bbf6daff88130e1698097b005b8d244e.zip |
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.
-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); } |