Source-Changes-HG archive

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

[src/trunk]: src/usr.bin/make make(1): remove macros MIN and MAX



details:   https://anonhg.NetBSD.org/src/rev/742400f296f3
branches:  trunk
changeset: 977464:742400f296f3
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sat Oct 24 20:51:49 2020 +0000

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

diffstat:

 usr.bin/make/buf.c  |   8 ++++----
 usr.bin/make/make.h |   9 +--------
 usr.bin/make/str.c  |   6 +++---
 usr.bin/make/var.c  |  19 ++++++++++---------
 4 files changed, 18 insertions(+), 24 deletions(-)

diffs (140 lines):

diff -r 9994403dec3a -r 742400f296f3 usr.bin/make/buf.c
--- a/usr.bin/make/buf.c        Sat Oct 24 20:29:40 2020 +0000
+++ b/usr.bin/make/buf.c        Sat Oct 24 20:51:49 2020 +0000
@@ -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 @@
     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);
     }
 
diff -r 9994403dec3a -r 742400f296f3 usr.bin/make/make.h
--- a/usr.bin/make/make.h       Sat Oct 24 20:29:40 2020 +0000
+++ b/usr.bin/make/make.h       Sat Oct 24 20:51:49 2020 +0000
@@ -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 @@
 #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
diff -r 9994403dec3a -r 742400f296f3 usr.bin/make/str.c
--- a/usr.bin/make/str.c        Sat Oct 24 20:29:40 2020 +0000
+++ b/usr.bin/make/str.c        Sat Oct 24 20:51:49 2020 +0000
@@ -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_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 *));
 
        /*
diff -r 9994403dec3a -r 742400f296f3 usr.bin/make/var.c
--- a/usr.bin/make/var.c        Sat Oct 24 20:29:40 2020 +0000
+++ b/usr.bin/make/var.c        Sat Oct 24 20:51:49 2020 +0000
@@ -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 @@
               int last)
 {
     Words words;
-    int start, end, step;
+    int len, start, end, step;
     int i;
 
     SepBuf buf;
@@ -1492,21 +1492,22 @@
      * 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;
     }
 



Home | Main Index | Thread Index | Old Index