diff options
author | harti <harti@FreeBSD.org> | 2005-02-03 11:36:19 +0000 |
---|---|---|
committer | harti <harti@FreeBSD.org> | 2005-02-03 11:36:19 +0000 |
commit | 0bc036b7934d9a43411e4299626181d21a0ce221 (patch) | |
tree | c68c95224e9c403b67ebdf762a41fd5bb85092f4 /usr.bin/make | |
parent | e500bbb4ffedabbfe39b2d52cfe764db9664c2c0 (diff) | |
download | FreeBSD-src-0bc036b7934d9a43411e4299626181d21a0ce221.zip FreeBSD-src-0bc036b7934d9a43411e4299626181d21a0ce221.tar.gz |
Get rid of a number of unneccessary memory allocations.
Submitted by: Max Okumoto <okumoto@ucsd.edu>
Diffstat (limited to 'usr.bin/make')
-rw-r--r-- | usr.bin/make/var_modify.c | 26 |
1 files changed, 10 insertions, 16 deletions
diff --git a/usr.bin/make/var_modify.c b/usr.bin/make/var_modify.c index 688cf87..59d0ed7 100644 --- a/usr.bin/make/var_modify.c +++ b/usr.bin/make/var_modify.c @@ -71,18 +71,13 @@ Boolean VarHead(const char *word, Boolean addSpace, Buffer *buf, void *dummy __unused) { char *slash; - char *buffer; - buffer = estrdup(word); - slash = strrchr(buffer, '/'); + slash = strrchr(word, '/'); if (slash != NULL) { if (addSpace) { Buf_AddByte(buf, (Byte)' '); } - *slash = '\0'; - Buf_AddBytes(buf, strlen (buffer), (Byte *)buffer); - free(buffer); - return (TRUE); + Buf_AddBytes(buf, slash - word, (Byte *)word); } else { /* * If no directory part, give . (q.v. the POSIX standard) @@ -93,7 +88,6 @@ VarHead(const char *word, Boolean addSpace, Buffer *buf, void *dummy __unused) Buf_AddByte(buf, (Byte)'.'); } } - free(buffer); return (TRUE); } @@ -122,7 +116,8 @@ VarTail(const char *word, Boolean addSpace, Buffer *buf, void *dummy __unused) } slash = strrchr(word, '/'); - if (slash++ != NULL) { + if (slash != NULL) { + slash++; Buf_AddBytes(buf, strlen(slash), (const Byte *)slash); } else { Buf_AddBytes(buf, strlen(word), (const Byte *)word); @@ -150,10 +145,11 @@ VarSuffix(const char *word, Boolean addSpace, Buffer *buf, void *dummy __unused) const char *dot; dot = strrchr(word, '.'); - if (dot++ != NULL) { + if (dot != NULL) { if (addSpace) { Buf_AddByte(buf, (Byte)' '); } + dot++; Buf_AddBytes(buf, strlen(dot), (const Byte *)dot); addSpace = TRUE; } @@ -178,20 +174,18 @@ VarSuffix(const char *word, Boolean addSpace, Buffer *buf, void *dummy __unused) Boolean VarRoot(const char *word, Boolean addSpace, Buffer *buf, void *dummy __unused) { - char *buffer; char *dot; if (addSpace) { Buf_AddByte(buf, (Byte)' '); } - buffer = estrdup(word); - dot = strrchr(buffer, '.'); + dot = strrchr(word, '.'); if (dot != NULL) { - *dot = '\0'; + Buf_AddBytes(buf, dot - word, (Byte *)word); + } else { + Buf_AddBytes(buf, strlen(word), (Byte *)word); } - Buf_AddBytes(buf, strlen(buffer), (Byte *)buffer); - free(buffer); return (TRUE); } |