diff options
author | jilles <jilles@FreeBSD.org> | 2010-11-23 22:17:39 +0000 |
---|---|---|
committer | jilles <jilles@FreeBSD.org> | 2010-11-23 22:17:39 +0000 |
commit | 7377de8f916e2389e9f1c47ca8f7de558aaca6ef (patch) | |
tree | ff9e8102b66741a601dc54d4455bad759b583a8b /bin/sh/cd.c | |
parent | 77837b201a907898ee7c79f6a8584102187a089a (diff) | |
download | FreeBSD-src-7377de8f916e2389e9f1c47ca8f7de558aaca6ef.zip FreeBSD-src-7377de8f916e2389e9f1c47ca8f7de558aaca6ef.tar.gz |
sh: Code size optimizations to "stack string" memory allocation:
* Prefer one CHECKSTRSPACE with multiple USTPUTC to multiple STPUTC.
* Add STPUTS macro (based on function) and use it instead of loops that add
nul-terminated strings to the stack string.
No functional change is intended, but code size is about 1K less on i386.
Diffstat (limited to 'bin/sh/cd.c')
-rw-r--r-- | bin/sh/cd.c | 12 |
1 files changed, 4 insertions, 8 deletions
diff --git a/bin/sh/cd.c b/bin/sh/cd.c index 2ac4b10..068dfb7 100644 --- a/bin/sh/cd.c +++ b/bin/sh/cd.c @@ -192,8 +192,7 @@ cdlogical(char *dest) STPUTC('/', p); first = 0; component = q; - while (*q) - STPUTC(*q++, p); + STPUTS(q, p); if (equal(component, "..")) continue; STACKSTRNUL(p); @@ -273,10 +272,8 @@ findcwd(char *dir) scopy(dir, cdcomppath); STARTSTACKSTR(new); if (*dir != '/') { - p = curdir; - while (*p) - STPUTC(*p++, new); - if (p[-1] == '/') + STPUTS(curdir, new); + if (STTOPC(new) == '/') STUNPUTC(new); } while ((p = getcomponent()) != NULL) { @@ -284,8 +281,7 @@ findcwd(char *dir) while (new > stackblock() && (STUNPUTC(new), *new) != '/'); } else if (*p != '\0' && ! equal(p, ".")) { STPUTC('/', new); - while (*p) - STPUTC(*p++, new); + STPUTS(p, new); } } if (new == stackblock()) |