Module Name:    src
Committed By:   rillig
Date:           Fri Jul 24 08:03:28 UTC 2020

Modified Files:
        src/usr.bin/make: var.c

Log Message:
make(1): allocate capturing groups for :C modifier statically

Since there are at most 10 capturing groups, it's easier to allocate them
on the stack.

To avoid growing the code size on x86_64, the matches have been moved to
the end of the struct, to keep the other offsets small.


To generate a diff of this commit:
cvs rdiff -u -r1.302 -r1.303 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.302 src/usr.bin/make/var.c:1.303
--- src/usr.bin/make/var.c:1.302	Fri Jul 24 07:59:35 2020
+++ src/usr.bin/make/var.c	Fri Jul 24 08:03:27 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: var.c,v 1.302 2020/07/24 07:59:35 rillig Exp $	*/
+/*	$NetBSD: var.c,v 1.303 2020/07/24 08:03:27 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -69,14 +69,14 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: var.c,v 1.302 2020/07/24 07:59:35 rillig Exp $";
+static char rcsid[] = "$NetBSD: var.c,v 1.303 2020/07/24 08:03:27 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.302 2020/07/24 07:59:35 rillig Exp $");
+__RCSID("$NetBSD: var.c,v 1.303 2020/07/24 08:03:27 rillig Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -1376,9 +1376,9 @@ VarREError(int reerr, regex_t *pat, cons
 typedef struct {
     regex_t	   re;
     int		   nsub;
-    regmatch_t 	  *matches;
     char 	  *replace;
     VarPatternFlags pflags;
+    regmatch_t 	  matches[10];
 } ModifyWord_SubstRegexArgs;
 
 /* Callback for ModifyWords to implement the :C/from/to/ modifier.
@@ -2530,12 +2530,10 @@ ApplyModifier_Regex(const char *mod, App
 	args.nsub = 1;
     if (args.nsub > 10)
 	args.nsub = 10;
-    args.matches = bmake_malloc(args.nsub * sizeof(regmatch_t));
     st->newStr = ModifyWords(st->ctxt, st->sep, oneBigWord, st->nstr,
 			     ModifyWord_SubstRegex, &args);
     regfree(&args.re);
     free(args.replace);
-    free(args.matches);
     return TRUE;
 }
 #endif

Reply via email to