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.
This commit is contained in:
rillig 2020-10-24 20:51:49 +00:00
parent 9bc6208f19
commit 12d3b8fc47
4 changed files with 18 additions and 24 deletions

View File

@ -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 *bytes, size_t bytes_len)
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);
}

View File

@ -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

View File

@ -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 expand)
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 *));
/*

View File

@ -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 oneBigWord, const char *str, int first,
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 oneBigWord, const char *str, int first,
* 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;
}