Module Name: src Committed By: sjg Date: Mon Oct 12 16:48:13 UTC 2015
Modified Files: src/usr.bin/make: var.c Log Message: The conditional expressions used with ':?' can be expensive eg. exists() does stat(2). If 'wantit' is FALSE, we are going to discard everything anyway, so skip evaluating the conditional and expanding either lhs or rhs. To generate a diff of this commit: cvs rdiff -u -r1.197 -r1.198 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.197 src/usr.bin/make/var.c:1.198 --- src/usr.bin/make/var.c:1.197 Sun Oct 11 04:51:24 2015 +++ src/usr.bin/make/var.c Mon Oct 12 16:48:13 2015 @@ -1,4 +1,4 @@ -/* $NetBSD: var.c,v 1.197 2015/10/11 04:51:24 sjg Exp $ */ +/* $NetBSD: var.c,v 1.198 2015/10/12 16:48:13 sjg Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1993 @@ -69,14 +69,14 @@ */ #ifndef MAKE_NATIVE -static char rcsid[] = "$NetBSD: var.c,v 1.197 2015/10/11 04:51:24 sjg Exp $"; +static char rcsid[] = "$NetBSD: var.c,v 1.198 2015/10/12 16:48:13 sjg 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.197 2015/10/11 04:51:24 sjg Exp $"); +__RCSID("$NetBSD: var.c,v 1.198 2015/10/12 16:48:13 sjg Exp $"); #endif #endif /* not lint */ #endif @@ -3238,17 +3238,22 @@ ApplyModifiers(char *nstr, const char *t int lhs_flags, rhs_flags; /* find ':', and then substitute accordingly */ - cond_rc = Cond_EvalExpression(NULL, v->name, &value, 0, FALSE); - if (cond_rc == COND_INVALID) { - lhs_flags = rhs_flags = VAR_NOSUBST; - } else if (value) { - lhs_flags = 0; - rhs_flags = VAR_NOSUBST; + if (wantit) { + cond_rc = Cond_EvalExpression(NULL, v->name, &value, 0, FALSE); + if (cond_rc == COND_INVALID) { + lhs_flags = rhs_flags = VAR_NOSUBST; + } else if (value) { + lhs_flags = 0; + rhs_flags = VAR_NOSUBST; + } else { + lhs_flags = VAR_NOSUBST; + rhs_flags = 0; + } } else { - lhs_flags = VAR_NOSUBST; - rhs_flags = 0; + /* we are just consuming and discarding */ + cond_rc = value = 0; + lhs_flags = rhs_flags = VAR_NOSUBST; } - pattern.flags = 0; cp = ++tstr;