Module Name: src Committed By: rillig Date: Sun Apr 28 15:10:19 UTC 2024
Modified Files: src/usr.bin/make: buf.c buf.h var.c Log Message: make: don't reallocate memory after evaluating an expression When an expression is evaluated, the resulting text is short-lived in almost all cases. In particular, the compaction neither affects the target names nor the global variable values, which are the prime candidates for permanent memory usage. To generate a diff of this commit: cvs rdiff -u -r1.57 -r1.58 src/usr.bin/make/buf.c cvs rdiff -u -r1.49 -r1.50 src/usr.bin/make/buf.h cvs rdiff -u -r1.1107 -r1.1108 src/usr.bin/make/var.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/usr.bin/make/buf.c diff -u src/usr.bin/make/buf.c:1.57 src/usr.bin/make/buf.c:1.58 --- src/usr.bin/make/buf.c:1.57 Tue Dec 19 19:33:39 2023 +++ src/usr.bin/make/buf.c Sun Apr 28 15:10:19 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: buf.c,v 1.57 2023/12/19 19:33:39 rillig Exp $ */ +/* $NetBSD: buf.c,v 1.58 2024/04/28 15:10:19 rillig Exp $ */ /* * Copyright (c) 1988, 1989, 1990 The Regents of the University of California. @@ -75,7 +75,7 @@ #include "make.h" /* "@(#)buf.c 8.1 (Berkeley) 6/6/93" */ -MAKE_RCSID("$NetBSD: buf.c,v 1.57 2023/12/19 19:33:39 rillig Exp $"); +MAKE_RCSID("$NetBSD: buf.c,v 1.58 2024/04/28 15:10:19 rillig Exp $"); /* Make space in the buffer for adding at least 16 more bytes. */ void @@ -187,30 +187,3 @@ Buf_DoneData(Buffer *buf) return data; } - -#ifndef BUF_COMPACT_LIMIT -# define BUF_COMPACT_LIMIT 128 /* worthwhile saving */ -#endif - -/* - * Return the data from the buffer. - * Leave the buffer itself in an indeterminate state. - * - * If the buffer size is much greater than its content, - * a new buffer will be allocated and the old one freed. - */ -char * -Buf_DoneDataCompact(Buffer *buf) -{ -#if BUF_COMPACT_LIMIT > 0 - if (buf->cap - buf->len >= BUF_COMPACT_LIMIT) { - /* We trust realloc to be smart */ - char *data = bmake_realloc(buf->data, buf->len + 1); - buf->data = NULL; - data[buf->len] = '\0'; /* XXX: unnecessary */ - Buf_Done(buf); - return data; - } -#endif - return Buf_DoneData(buf); -} Index: src/usr.bin/make/buf.h diff -u src/usr.bin/make/buf.h:1.49 src/usr.bin/make/buf.h:1.50 --- src/usr.bin/make/buf.h:1.49 Tue Dec 19 19:33:39 2023 +++ src/usr.bin/make/buf.h Sun Apr 28 15:10:19 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: buf.h,v 1.49 2023/12/19 19:33:39 rillig Exp $ */ +/* $NetBSD: buf.h,v 1.50 2024/04/28 15:10:19 rillig Exp $ */ /* * Copyright (c) 1988, 1989, 1990 The Regents of the University of California. @@ -124,6 +124,5 @@ void Buf_Init(Buffer *); void Buf_InitSize(Buffer *, size_t); void Buf_Done(Buffer *); char *Buf_DoneData(Buffer *) MAKE_ATTR_USE; -char *Buf_DoneDataCompact(Buffer *) MAKE_ATTR_USE; #endif Index: src/usr.bin/make/var.c diff -u src/usr.bin/make/var.c:1.1107 src/usr.bin/make/var.c:1.1108 --- src/usr.bin/make/var.c:1.1107 Sat Apr 27 21:26:23 2024 +++ src/usr.bin/make/var.c Sun Apr 28 15:10:19 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: var.c,v 1.1107 2024/04/27 21:26:23 rillig Exp $ */ +/* $NetBSD: var.c,v 1.1108 2024/04/28 15:10:19 rillig Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1993 @@ -132,7 +132,7 @@ #include "metachar.h" /* "@(#)var.c 8.3 (Berkeley) 3/19/94" */ -MAKE_RCSID("$NetBSD: var.c,v 1.1107 2024/04/27 21:26:23 rillig Exp $"); +MAKE_RCSID("$NetBSD: var.c,v 1.1108 2024/04/28 15:10:19 rillig Exp $"); /* * Variables are defined using one of the VAR=value assignments. Their @@ -4731,7 +4731,7 @@ Var_Subst(const char *str, GNode *scope, VarSubstPlain(&p, &res); } - return Buf_DoneDataCompact(&res); + return Buf_DoneData(&res); } void