Module Name:    src
Committed By:   rillig
Date:           Sat Oct 24 20:51:49 UTC 2020

Modified Files:
        src/usr.bin/make: buf.c make.h str.c var.c

Log Message:
make(1): remove macros MIN and MAX

These macros typically evaluate one of their arguments twice.  Until
2020-08-31, they had not parenthesized their arguments properly.  They
are only used in a few places, therefore it doesn't hurt much to have
them expanded.


To generate a diff of this commit:
cvs rdiff -u -r1.41 -r1.42 src/usr.bin/make/buf.c
cvs rdiff -u -r1.170 -r1.171 src/usr.bin/make/make.h
cvs rdiff -u -r1.69 -r1.70 src/usr.bin/make/str.c
cvs rdiff -u -r1.582 -r1.583 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/buf.c
diff -u src/usr.bin/make/buf.c:1.41 src/usr.bin/make/buf.c:1.42
--- src/usr.bin/make/buf.c:1.41	Sat Oct 24 04:27:24 2020
+++ src/usr.bin/make/buf.c	Sat Oct 24 20:51:49 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: buf.c,v 1.41 2020/10/24 04:27:24 rillig Exp $	*/
+/*	$NetBSD: buf.c,v 1.42 2020/10/24 20:51:49 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -75,13 +75,13 @@
 #include "make.h"
 
 /*	"@(#)buf.c	8.1 (Berkeley) 6/6/93"	*/
-MAKE_RCSID("$NetBSD: buf.c,v 1.41 2020/10/24 04:27:24 rillig Exp $");
+MAKE_RCSID("$NetBSD: buf.c,v 1.42 2020/10/24 20:51:49 rillig Exp $");
 
 /* Make space in the buffer for adding a single byte. */
 void
 Buf_Expand_1(Buffer *buf)
 {
-    buf->cap += MAX(buf->cap, 16);
+    buf->cap += buf->cap > 16 ? buf->cap : 16;
     buf->data = bmake_realloc(buf->data, buf->cap);
 }
 
@@ -93,7 +93,7 @@ Buf_AddBytes(Buffer *buf, const char *by
     char *end;
 
     if (__predict_false(old_len + bytes_len >= buf->cap)) {
-	buf->cap += MAX(buf->cap, bytes_len + 16);
+	buf->cap += buf->cap > bytes_len + 16 ? buf->cap : bytes_len + 16;
 	buf->data = bmake_realloc(buf->data, buf->cap);
     }
 

Index: src/usr.bin/make/make.h
diff -u src/usr.bin/make/make.h:1.170 src/usr.bin/make/make.h:1.171
--- src/usr.bin/make/make.h:1.170	Sat Oct 24 20:29:40 2020
+++ src/usr.bin/make/make.h	Sat Oct 24 20:51:49 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: make.h,v 1.170 2020/10/24 20:29:40 rillig Exp $	*/
+/*	$NetBSD: make.h,v 1.171 2020/10/24 20:51:49 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -604,13 +604,6 @@ GNode_IsTarget(const GNode *gn)
 #define UNCONST(ptr)	(void *)(ptr)
 #endif
 
-#ifndef MIN
-#define MIN(a, b) (((a) < (b)) ? (a) : (b))
-#endif
-#ifndef MAX
-#define MAX(a, b) (((a) > (b)) ? (a) : (b))
-#endif
-
 /* At least GNU/Hurd systems lack hardcoded MAXPATHLEN/PATH_MAX */
 #include <limits.h>
 #ifndef MAXPATHLEN

Index: src/usr.bin/make/str.c
diff -u src/usr.bin/make/str.c:1.69 src/usr.bin/make/str.c:1.70
--- src/usr.bin/make/str.c:1.69	Thu Oct 22 05:50:02 2020
+++ src/usr.bin/make/str.c	Sat Oct 24 20:51:49 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: str.c,v 1.69 2020/10/22 05:50:02 rillig Exp $	*/
+/*	$NetBSD: str.c,v 1.70 2020/10/24 20:51:49 rillig Exp $	*/
 
 /*-
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -71,7 +71,7 @@
 #include "make.h"
 
 /*	"@(#)str.c	5.8 (Berkeley) 6/1/90"	*/
-MAKE_RCSID("$NetBSD: str.c,v 1.69 2020/10/22 05:50:02 rillig Exp $");
+MAKE_RCSID("$NetBSD: str.c,v 1.70 2020/10/24 20:51:49 rillig Exp $");
 
 /* Return the concatenation of s1 and s2, freshly allocated. */
 char *
@@ -147,7 +147,7 @@ Str_Words(const char *str, Boolean expan
 	str_len = strlen(str);
 	words_buf = bmake_malloc(strlen(str) + 1);
 
-	words_cap = MAX((str_len / 5), 50);
+	words_cap = str_len / 5 > 50 ? str_len / 5 : 50;
 	words = bmake_malloc((words_cap + 1) * sizeof(char *));
 
 	/*

Index: src/usr.bin/make/var.c
diff -u src/usr.bin/make/var.c:1.582 src/usr.bin/make/var.c:1.583
--- src/usr.bin/make/var.c:1.582	Fri Oct 23 13:38:17 2020
+++ src/usr.bin/make/var.c	Sat Oct 24 20:51:49 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: var.c,v 1.582 2020/10/23 13:38:17 rillig Exp $	*/
+/*	$NetBSD: var.c,v 1.583 2020/10/24 20:51:49 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -121,7 +121,7 @@
 #include    "metachar.h"
 
 /*	"@(#)var.c	8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: var.c,v 1.582 2020/10/23 13:38:17 rillig Exp $");
+MAKE_RCSID("$NetBSD: var.c,v 1.583 2020/10/24 20:51:49 rillig Exp $");
 
 #define VAR_DEBUG1(fmt, arg1) DEBUG1(VAR, fmt, arg1)
 #define VAR_DEBUG2(fmt, arg1, arg2) DEBUG2(VAR, fmt, arg1, arg2)
@@ -1470,7 +1470,7 @@ VarSelectWords(char sep, Boolean oneBigW
 	       int last)
 {
     Words words;
-    int start, end, step;
+    int len, start, end, step;
     int i;
 
     SepBuf buf;
@@ -1492,21 +1492,22 @@ VarSelectWords(char sep, Boolean oneBigW
      * If first or last are negative, convert them to the positive equivalents
      * (-1 gets converted to ac, -2 gets converted to (ac - 1), etc.).
      */
+    len = (int)words.len;
     if (first < 0)
-	first += (int)words.len + 1;
+	first += len + 1;
     if (last < 0)
-	last += (int)words.len + 1;
+	last += len + 1;
 
     /*
      * We avoid scanning more of the list than we need to.
      */
     if (first > last) {
-	start = MIN((int)words.len, first) - 1;
-	end = MAX(0, last - 1);
+	start = (first > len ? len : first) - 1;
+	end = last < 1 ? 0 : last - 1;
 	step = -1;
     } else {
-	start = MAX(0, first - 1);
-	end = MIN((int)words.len, last);
+	start = first < 1 ? 0 : first - 1;
+	end = last > len ? len : last;
 	step = 1;
     }
 

Reply via email to