Module Name: src Committed By: rillig Date: Sat Aug 1 18:36:49 UTC 2020
Modified Files: src/usr.bin/make: var.c Log Message: make(1): inline and untangle the code for the :range modifier There's no need to keep the result from brk_string in memory until the buffer has been filled with the range. The only thing necessary from brk_string is the number of words. To generate a diff of this commit: cvs rdiff -u -r1.385 -r1.386 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/var.c diff -u src/usr.bin/make/var.c:1.385 src/usr.bin/make/var.c:1.386 --- src/usr.bin/make/var.c:1.385 Sat Aug 1 18:14:08 2020 +++ src/usr.bin/make/var.c Sat Aug 1 18:36:49 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: var.c,v 1.385 2020/08/01 18:14:08 rillig Exp $ */ +/* $NetBSD: var.c,v 1.386 2020/08/01 18:36:49 rillig Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1993 @@ -69,14 +69,14 @@ */ #ifndef MAKE_NATIVE -static char rcsid[] = "$NetBSD: var.c,v 1.385 2020/08/01 18:14:08 rillig Exp $"; +static char rcsid[] = "$NetBSD: var.c,v 1.386 2020/08/01 18:36:49 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.385 2020/08/01 18:14:08 rillig Exp $"); +__RCSID("$NetBSD: var.c,v 1.386 2020/08/01 18:36:49 rillig Exp $"); #endif #endif /* not lint */ #endif @@ -1720,47 +1720,6 @@ VarUniq(const char *str) return Buf_Destroy(&buf, FALSE); } -/*- - *----------------------------------------------------------------------- - * VarRange -- - * Return an integer sequence - * - * Input: - * str String whose words provide default range - * ac range length, if 0 use str words - * - * Side Effects: - * None. - * - *----------------------------------------------------------------------- - */ -static char * -VarRange(const char *str, int ac) -{ - Buffer buf; /* Buffer for new string */ - char **av; /* List of words to affect */ - char *as; /* Word list memory */ - int i; - - Buf_Init(&buf, 0); - if (ac > 0) { - as = NULL; - av = NULL; - } else { - av = brk_string(str, &ac, FALSE, &as); - } - for (i = 0; i < ac; i++) { - if (i != 0) - Buf_AddByte(&buf, ' '); - Buf_AddInt(&buf, 1 + i); - } - - free(as); - free(av); - - return Buf_Destroy(&buf, FALSE); -} - /*- * Parse a text part of a modifier such as the "from" and "to" in :S/from/to/ @@ -2264,7 +2223,8 @@ ApplyModifier_Exclam(const char *mod, Ap return AMR_OK; } -/* :range */ +/* The :range modifier generates an integer sequence as long as the words. + * The :range=7 modifier generates an integer sequence from 1 to 7. */ static ApplyModifierResult ApplyModifier_Range(const char *mod, ApplyModifiersState *st) { @@ -2280,7 +2240,25 @@ ApplyModifier_Range(const char *mod, App n = 0; st->next = mod + 5; } - st->newVal = VarRange(st->val, n); + + if (n == 0) { + char *as; + char **av = brk_string(st->val, &n, FALSE, &as); + free(as); + free(av); + } + + Buffer buf; + Buf_Init(&buf, 0); + + int i; + for (i = 0; i < n; i++) { + if (i != 0) + Buf_AddByte(&buf, ' '); + Buf_AddInt(&buf, 1 + i); + } + + st->newVal = Buf_Destroy(&buf, FALSE); return AMR_OK; }