Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/make make(1): avoid memory allocation for oneBigWord...



details:   https://anonhg.NetBSD.org/src/rev/e31f98c3975a
branches:  trunk
changeset: 936406:e31f98c3975a
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sun Jul 26 15:53:01 2020 +0000

description:
make(1): avoid memory allocation for oneBigWord in modifiers

diffstat:

 usr.bin/make/var.c |  24 +++++++++++-------------
 1 files changed, 11 insertions(+), 13 deletions(-)

diffs (58 lines):

diff -r 16e71bbd5beb -r e31f98c3975a usr.bin/make/var.c
--- a/usr.bin/make/var.c        Sun Jul 26 15:47:27 2020 +0000
+++ b/usr.bin/make/var.c        Sun Jul 26 15:53:01 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: var.c,v 1.315 2020/07/26 15:37:44 rillig Exp $ */
+/*     $NetBSD: var.c,v 1.316 2020/07/26 15:53:01 rillig Exp $ */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -69,14 +69,14 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: var.c,v 1.315 2020/07/26 15:37:44 rillig Exp $";
+static char rcsid[] = "$NetBSD: var.c,v 1.316 2020/07/26 15:53:01 rillig Exp $";
 #else
 #include <sys/cdefs.h>
 #ifndef lint
 #if 0
 static char sccsid[] = "@(#)var.c      8.3 (Berkeley) 3/19/94";
 #else
-__RCSID("$NetBSD: var.c,v 1.315 2020/07/26 15:37:44 rillig Exp $");
+__RCSID("$NetBSD: var.c,v 1.316 2020/07/26 15:53:01 rillig Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -1595,6 +1595,13 @@
 ModifyWords(GNode *ctx, Byte sep, Boolean oneBigWord,
            const char *str, ModifyWordsCallback modifyWord, void *data)
 {
+    if (oneBigWord) {
+       SepBuf result;
+       SepBuf_Init(&result, sep);
+       modifyWord(str, &result, data);
+       return SepBuf_Destroy(&result, FALSE);
+    }
+
     SepBuf result;
     char **av;                 /* word list */
     char *as;                  /* word list memory */
@@ -1602,16 +1609,7 @@
 
     SepBuf_Init(&result, sep);
 
-    if (oneBigWord) {
-       /* fake what brk_string() would do if there were only one word */
-       ac = 1;
-       av = bmake_malloc((ac + 1) * sizeof(char *));
-       as = bmake_strdup(str);
-       av[0] = as;
-       av[1] = NULL;
-    } else {
-       av = brk_string(str, &ac, FALSE, &as);
-    }
+    av = brk_string(str, &ac, FALSE, &as);
 
     if (DEBUG(VAR)) {
        fprintf(debug_file, "ModifyWords: split \"%s\" into %d words\n",



Home | Main Index | Thread Index | Old Index