Source-Changes-HG archive

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

[src/trunk]: src/usr.bin/make The conditional expressions used with ':?' can ...



details:   https://anonhg.NetBSD.org/src/rev/39f977f7db03
branches:  trunk
changeset: 340945:39f977f7db03
user:      sjg <sjg%NetBSD.org@localhost>
date:      Mon Oct 12 16:48:13 2015 +0000

description:
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.

diffstat:

 usr.bin/make/var.c |  29 +++++++++++++++++------------
 1 files changed, 17 insertions(+), 12 deletions(-)

diffs (58 lines):

diff -r 5480fef120ee -r 39f977f7db03 usr.bin/make/var.c
--- a/usr.bin/make/var.c        Mon Oct 12 12:07:24 2015 +0000
+++ b/usr.bin/make/var.c        Mon Oct 12 16:48:13 2015 +0000
@@ -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 @@
                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) {
+               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 {
+                   /* we are just consuming and discarding */
+                   cond_rc = value = 0;
                    lhs_flags = rhs_flags = VAR_NOSUBST;
-               } else if (value) {
-                   lhs_flags = 0;
-                   rhs_flags = VAR_NOSUBST;
-               } else {
-                   lhs_flags = VAR_NOSUBST;
-                   rhs_flags = 0;
                }
-
                pattern.flags = 0;
 
                cp = ++tstr;



Home | Main Index | Thread Index | Old Index