8000 Standardize on using the Min, Max, and Abs macros that are in our c.h… · postgrespro/postgres@380bd04 · GitHub
[go: up one dir, main page]

Skip to content

Commit 380bd04

Browse files
committed
Standardize on using the Min, Max, and Abs macros that are in our c.h file,
getting rid of numerous ad-hoc versions that have popped up in various places. Shortens code and avoids conflict with Windows min() and max() macros.
1 parent a171fc1 commit 380bd04

File tree

22 files changed

+34
-77
lines changed

22 files changed

+34
-77
lines changed

contrib/cube/cube.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515

1616
#include "cubedata.h"
1717

18-
#define abs(a) ((a) < (0) ? (-a) : (a))
19-
2018
extern int cube_yyparse();
2119
extern void cube_yyerror(const char *message);
2220
extern void cube_scanner_init(const char *str);
@@ -683,7 +681,7 @@ cube_size(NDBOX * a)
683681

684682
*result = 1.0;
685683
for (i = 0, j = a->dim; i < a->dim; i++, j++)
686-
*result = (*result) * abs((a->x[j] - a->x[i]));
684+
*result = (*result) * Abs((a->x[j] - a->x[i]));
687685

688686
return (result);
689687
}
@@ -700,7 +698,7 @@ rt_cube_size(NDBOX * a, double *size)
700698
{
701699
*size = 1.0;
702700
for (i = 0, j = a->dim; i < a->dim; i++, j++)
703-
*size = (*size) * abs((a->x[j] - a->x[i]));
701+
*size = (*size) * Abs((a->x[j] - a->x[i]));
704702
}
705703
return;
706704
}

contrib/intarray/_int.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,6 @@
1414
/* number ranges for compression */
1515
#define MAXNUMRANGE 100
1616

17-
#define max(a,b) ((a) > (b) ? (a) : (b))
18-
#define min(a,b) ((a) <= (b) ? (a) : (b))
19-
#define abs(a) ((a) < (0) ? -(a) : (a))
20-
2117
/* dimension of array */
2218
#define NDIM 1
2319

contrib/intarray/_int_gist.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ g_int_picksplit(PG_FUNCTION_ARGS)
425425
union_d = inner_int_union(datum_r, datum_alpha);
426426
rt__int_size(union_d, &size_beta);
427427
pfree(union_d);
428-
costvector[i - 1].cost = abs((size_alpha - size_l) - (size_beta - size_r));
428+
costvector[i - 1].cost = Abs((size_alpha - size_l) - (size_beta - size_r));
429429
}
430430
qsort((void *) costvector, maxoff, sizeof(SPLITCOST), comparecost);
431431

contrib/intarray/_int_tool.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ inner_int_inter(ArrayType *a, ArrayType *b)
137137
nb = ARRNELEMS(b);
138138
da = ARRPTR(a);
139139
db = ARRPTR(b);
140-
r = new_intArrayType(min(na, nb));
140+
r = new_intArrayType(Min(na, nb));
141141
dr = ARRPTR(r);
142142

143143
i = j = 0;

contrib/intarray/_intbig_gist.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ g_intbig_picksplit(PG_FUNCTION_ARGS)
402402
_j = GETENTRY(entryvec, j);
403403
size_alpha = hemdist(datum_l, _j);
404404
size_beta = hemdist(datum_r, _j);
405-
costvector[j - 1].cost = abs(size_alpha - size_beta);
405+
costvector[j - 1].cost = Abs(size_alpha - size_beta);
406406
}
407407
qsort((void *) costvector, maxoff, sizeof(SPLITCOST), comparecost);
408408

contrib/ltree/_ltree_gist.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ _ltree_picksplit(PG_FUNCTION_ARGS)
361361
_j = GETENTRY(entryvec, j);
362362
size_alpha = hemdist(datum_l, _j);
363363
size_beta = hemdist(datum_r, _j);
364-
costvector[j - 1].cost = abs(size_alpha - size_beta);
364+
costvector[j - 1].cost = Abs(size_alpha - size_beta);
365365
}
366366
qsort((void *) costvector, maxoff, sizeof(SPLITCOST), comparecost);
367367

contrib/ltree/ltree.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -78,15 +78,6 @@ typedef struct
7878

7979
#define LQUERY_HASNOT 0x01
8080

81-
#ifndef max
82-
#define max(a,b) ((a) > (b) ? (a) : (b))
83-
#endif
84-
#ifndef min
85-
#define min(a,b) ((a) <= (b) ? (a) : (b))
86-
#endif
87-
#ifndef abs
88-
#define abs(a) ((a) < (0) ? -(a) : (a))
89-
#endif
9081
#define ISALNUM(x) ( isalnum((unsigned char)(x)) || (x) == '_' )
9182

9283
/* full text query */

contrib/ltree/ltree_gist.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ ltree_penalty(PG_FUNCTION_ARGS)
259259
cmpl = ltree_compare(LTG_GETLNODE(origval), LTG_GETLNODE(newval));
260260
cmpr = ltree_compare(LTG_GETRNODE(newval), LTG_GETRNODE(origval));
261261

262-
*penalty = max(cmpl, 0) + max(cmpr, 0);
262+
*penalty = Max(cmpl, 0) + Max(cmpr, 0);
263263

264264
PG_RETURN_POINTER(penalty);
265265
}
@@ -537,7 +537,7 @@ gist_tqcmp(ltree * t, lquery * q)
537537
while (an > 0 && bn > 0)
538538
{
539539
bl = LQL_FIRST(ql);
540-
if ((res = strncmp(al->name, bl->name, min(al->len, bl->len))) == 0)
540+
if ((res = strncmp(al->name, bl->name, Min(al->len, bl->len))) == 0)
541541
{
542542
if (al->len != bl->len)
543543
return al->len - bl->len;

contrib/ltree/ltree_op.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ ltree_compare(const ltree * a, const ltree * b)
5555

5656
while (an > 0 && bn > 0)
5757
{
58-
if ((res = strncmp(al->name, bl->name, min(al->len, bl->len))) == 0)
58+
if ((res = strncmp(al->name, bl->name, Min(al->len, bl->len))) == 0)
5959
{
6060
if (al->len != bl->len)
6161
return (al->len - bl->len) * 10 * (an + 1);
@@ -443,7 +443,7 @@ lca_inner(ltree ** a, int len)
443443
l2 = LTREE_FIRST(*ptr);
444444
tmp = num;
445445
num = 0;
446-
for (i = 0; i < min(tmp, (*ptr)->numlevel - 1); i++)
446+
for (i = 0; i < Min(tmp, (*ptr)->numlevel - 1); i++)
447447
{
448448
if (l1->len == l2->len && strncmp(l1->name, l2->name, l1->len) == 0)
449449
num = i + 1;

contrib/miscutil/misc_utils.c

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,6 @@
3030

3131
#include "misc_utils.h"
3232

33-
#undef MIN
34-
#define MIN(x,y) ((x)<=(y) ? (x) : (y))
35-
3633

3734
int
3835
backend_pid()
@@ -48,15 +45,15 @@ unlisten(char *relname)
4845
}
4946

5047
int
51-
max(int x, int y)
48+
int4max(int x, int y)
5249
{
53-
return ((x > y) ? x : y);
50+
return Max(x, y);
5451
}
5552

5653
int
57-
min(int x, int y)
54+
int4min(int x, int y)
5855
{
59-
return ((x < y) ? x : y);
56+
return Min(x, y);
6057
}
6158

6259
/*
@@ -84,7 +81,7 @@ active_listeners(text *relname)
8481
if (relname && (VARSIZE(relname) > VARHDRSZ))
8582
{
8683
MemSet(listen_name, 0, NAMEDATALEN);
87-
len = MIN(VARSIZE(relname) - VARHDRSZ, NAMEDATALEN - 1);
84+
len = Min(VARSIZE(relname) - VARHDRSZ, NAMEDATALEN - 1);
8885
memcpy(listen_name, VARDATA(relname), len);
8986
ScanKeyInit(&key,
908 396E 7
Anum_pg_listener_relname,

0 commit comments

Comments
 (0)
0