diff options
author | jilles <jilles@FreeBSD.org> | 2010-12-27 22:18:27 +0000 |
---|---|---|
committer | jilles <jilles@FreeBSD.org> | 2010-12-27 22:18:27 +0000 |
commit | f6812a9bf2e3848d63c02126ebcf725221fc8fff (patch) | |
tree | 4eb97f94782e379552bd3c47f3c0116d4b7abcbb /bin/sh/memalloc.c | |
parent | 7d9fa04b1acb73718093971c279bd3dc314c6810 (diff) | |
download | FreeBSD-src-f6812a9bf2e3848d63c02126ebcf725221fc8fff.zip FreeBSD-src-f6812a9bf2e3848d63c02126ebcf725221fc8fff.tar.gz |
sh: Simplify "stack string" code slightly.
Maintain a pointer to the end of the stack string area instead of how much
space is left. This simplifies the macros in memalloc.h. The places where
the new variable must be updated are only where the memory area is created,
destroyed or resized.
Diffstat (limited to 'bin/sh/memalloc.c')
-rw-r--r-- | bin/sh/memalloc.c | 21 |
1 files changed, 6 insertions, 15 deletions
diff --git a/bin/sh/memalloc.c b/bin/sh/memalloc.c index 2571a7e..3ee104c 100644 --- a/bin/sh/memalloc.c +++ b/bin/sh/memalloc.c @@ -127,7 +127,7 @@ static struct stack_block *stackp; static struct stackmark *markp; char *stacknxt; int stacknleft; -int sstrnleft; +char *sstrend; static void @@ -146,6 +146,7 @@ stnewblock(int nbytes) sp->prev = stackp; stacknxt = SPACE(sp); stacknleft = allocsize - (stacknxt - (char*)sp); + sstrend = stacknxt + stacknleft; stackp = sp; INTON; } @@ -204,6 +205,7 @@ popstackmark(struct stackmark *mark) } stacknxt = mark->stacknxt; stacknleft = mark->stacknleft; + sstrend = stacknxt + stacknleft; INTON; } @@ -250,6 +252,7 @@ growstackblock(int min) stackp = sp; stacknxt = SPACE(sp); stacknleft = newlen - (stacknxt - (char*)sp); + sstrend = stacknxt + stacknleft; /* * Stack marks pointing to the start of the old block @@ -306,7 +309,6 @@ static char * growstrstackblock(int n, int min) { growstackblock(min); - sstrnleft = stackblocksize() - n; return stackblock() + n; } @@ -325,31 +327,20 @@ growstackstr(void) */ char * -makestrspace(int min) +makestrspace(int min, char *p) { int len; - len = stackblocksize() - sstrnleft; + len = p - stackblock(); return (growstrstackblock(len, min)); } - -void -ungrabstackstr(char *s, char *p) -{ - stacknleft += stacknxt - s; - stacknxt = s; - sstrnleft = stacknleft - (p - s); -} - - char * stputbin(const char *data, int len, char *p) { CHECKSTRSPACE(len, p); memcpy(p, data, len); - sstrnleft -= len; return (p + len); } |