Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.bin/make Reduce the calls to realloc from brk_string by ...
details: https://anonhg.NetBSD.org/src/rev/a3b2363d51ac
branches: trunk
changeset: 326676:a3b2363d51ac
user: sjg <sjg%NetBSD.org@localhost>
date: Wed Feb 12 01:35:56 2014 +0000
description:
Reduce the calls to realloc from brk_string by basing initial argmax guess
on length of input.
Reviewed by: christos
diffstat:
usr.bin/make/str.c | 14 ++++++++++----
1 files changed, 10 insertions(+), 4 deletions(-)
diffs (48 lines):
diff -r ac1cc5aa2fb0 -r a3b2363d51ac usr.bin/make/str.c
--- a/usr.bin/make/str.c Tue Feb 11 22:48:25 2014 +0000
+++ b/usr.bin/make/str.c Wed Feb 12 01:35:56 2014 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: str.c,v 1.34 2012/03/03 23:16:47 dholland Exp $ */
+/* $NetBSD: str.c,v 1.35 2014/02/12 01:35:56 sjg Exp $ */
/*-
* Copyright (c) 1988, 1989, 1990, 1993
@@ -69,14 +69,14 @@
*/
#ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: str.c,v 1.34 2012/03/03 23:16:47 dholland Exp $";
+static char rcsid[] = "$NetBSD: str.c,v 1.35 2014/02/12 01:35:56 sjg Exp $";
#else
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)str.c 5.8 (Berkeley) 6/1/90";
#else
-__RCSID("$NetBSD: str.c,v 1.34 2012/03/03 23:16:47 dholland Exp $");
+__RCSID("$NetBSD: str.c,v 1.35 2014/02/12 01:35:56 sjg Exp $");
#endif
#endif /* not lint */
#endif
@@ -145,7 +145,7 @@
const char *p;
int len;
int argmax = 50, curlen = 0;
- char **argv = bmake_malloc((argmax + 1) * sizeof(char *));
+ char **argv;
/* skip leading space chars. */
for (; *str == ' ' || *str == '\t'; ++str)
@@ -156,6 +156,12 @@
*buffer = bmake_malloc(curlen = len);
/*
+ * initial argmax based on len
+ */
+ argmax = MAX((len / 5), 50);
+ argv = bmake_malloc((argmax + 1) * sizeof(char *));
+
+ /*
* copy the string; at the same time, parse backslashes,
* quotes and build the argument list.
*/
Home |
Main Index |
Thread Index |
Old Index