From b6733f7f245fd9691b1312db4aa5bc7e982c575f Mon Sep 17 00:00:00 2001 From: Stefan Kangas Date: Sun, 19 Jan 2025 17:04:12 +0100 Subject: [PATCH] Prefer the 'min'/'max' macros where possible * src/composite.c (find_automatic_composition): * src/lisp.h (clip_to_bounds): * src/pgtkfns.c (PATH_MAX_LEN): * src/profiler.c (approximate_median): * src/unexmacosx.c (unexec_write_zero, unexec_copy, unexec_realloc): * src/xdisp.c (get_nearby_bol_pos): Prefer the 'min' and 'max' macros. (cherry picked from commit c37aa3df9d84325924a7a163271154447dfc0cfd) --- src/composite.c | 2 +- src/lisp.h | 2 +- src/pgtkfns.c | 3 +-- src/profiler.c | 4 ++-- src/unexmacosx.c | 6 +++--- src/xdisp.c | 4 ++-- 6 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/composite.c b/src/composite.c index f857dbf77ee..2ef72a33d2e 100644 --- a/src/composite.c +++ b/src/composite.c @@ -1676,7 +1676,7 @@ find_automatic_composition (ptrdiff_t pos, ptrdiff_t limit, ptrdiff_t backlim, } else { - head = backlim < 0 ? 0 : backlim, tail = SCHARS (string), stop = -1; + head = max (backlim, 0), tail = SCHARS (string), stop = -1; cur.pos_byte = string_char_to_byte (string, cur.pos); cur.p = SDATA (string) + cur.pos_byte; } diff --git a/src/lisp.h b/src/lisp.h index c9f9f17e0db..d0354d83629 100644 --- a/src/lisp.h +++ b/src/lisp.h @@ -1362,7 +1362,7 @@ EQ (Lisp_Object x, Lisp_Object y) INLINE intmax_t clip_to_bounds (intmax_t lower, intmax_t num, intmax_t upper) { - return num < lower ? lower : num <= upper ? num : upper; + return num < lower ? lower : min (num, upper); } /* Construct a Lisp_Object from a value or address. */ diff --git a/src/pgtkfns.c b/src/pgtkfns.c index 9251e137f09..21456f4f489 100644 --- a/src/pgtkfns.c +++ b/src/pgtkfns.c @@ -1782,8 +1782,7 @@ Some window managers may refuse to restack windows. */) #define PATH_FOR_CLASS_TYPE "/org/gnu/emacs/defaults-by-class/" #define PATH_PREFIX_FOR_NAME_TYPE "/org/gnu/emacs/defaults-by-name/" #define PATH_MAX_LEN \ - (sizeof PATH_FOR_CLASS_TYPE > sizeof PATH_PREFIX_FOR_NAME_TYPE ? \ - sizeof PATH_FOR_CLASS_TYPE : sizeof PATH_PREFIX_FOR_NAME_TYPE) + (max (sizeof PATH_FOR_CLASS_TYPE, sizeof PATH_PREFIX_FOR_NAME_TYPE)) static inline int pgtk_is_lower_char (int c) diff --git a/src/profiler.c b/src/profiler.c index 4c88f676fbd..03e8d007e9f 100644 --- a/src/profiler.c +++ b/src/profiler.c @@ -238,8 +238,8 @@ approximate_median (log_t *log, int start, int size) EMACS_INT i3 = approximate_median (log, start2 + newsize, size - 2 * newsize); return (i1 < i2 - ? (i2 < i3 ? i2 : (i1 < i3 ? i3 : i1)) - : (i1 < i3 ? i1 : (i2 < i3 ? i3 : i2))); + ? (i2 < i3 ? i2 : max (i1, i3)) + : (i1 < i3 ? i1 : max (i2, i3))); } } diff --git a/src/unexmacosx.c b/src/unexmacosx.c index f453f8ea7bb..10524224711 100644 --- a/src/unexmacosx.c +++ b/src/unexmacosx.c @@ -250,7 +250,7 @@ unexec_write_zero (off_t dest, size_t count) while (count > 0) { - bytes = count > UNEXEC_COPY_BUFSZ ? UNEXEC_COPY_BUFSZ : count; + bytes = min (count, UNEXEC_COPY_BUFSZ); if (write (outfd, buf, bytes) != bytes) return 0; count -= bytes; @@ -278,7 +278,7 @@ unexec_copy (off_t dest, off_t src, ssize_t count) while (count > 0) { - bytes_to_read = count > UNEXEC_COPY_BUFSZ ? UNEXEC_COPY_BUFSZ : count; + bytes_to_read = min (count, UNEXEC_COPY_BUFSZ); bytes_read = read (infd, buf, bytes_to_read); if (bytes_read <= 0) return 0; @@ -1355,7 +1355,7 @@ unexec_realloc (void *old_ptr, size_t new_size) if (ptr_in_unexec_regions (old_ptr)) { size_t old_size = ((unexec_malloc_header_t *) old_ptr)[-1].u.size; - size_t size = new_size > old_size ? old_size : new_size; + size_t size = min (new_size, old_size); p = malloc (new_size); if (size) diff --git a/src/xdisp.c b/src/xdisp.c index f464ed6948c..830c1e3b95a 100644 --- a/src/xdisp.c +++ b/src/xdisp.c @@ -3670,7 +3670,7 @@ get_nearby_bol_pos (ptrdiff_t pos) for (dist = 500; dist <= 500000; dist *= 10) { pos_bytepos = pos == BEGV ? BEGV_BYTE : CHAR_TO_BYTE (pos); - start = pos - dist < BEGV ? BEGV : pos - dist; + start = max (pos - dist, BEGV); for (cur = start; cur < pos; cur = next) { next = find_newline1 (cur, CHAR_TO_BYTE (cur), @@ -3684,7 +3684,7 @@ get_nearby_bol_pos (ptrdiff_t pos) if (bol >= BEGV || start == BEGV) break; else - pos = pos - dist < BEGV ? BEGV : pos - dist; + pos = max (pos - dist, BEGV); } eassert (bol <= init_pos); return bol; -- 2.39.5