From: Stefan Kangas Date: Tue, 9 Jan 2024 06:55:51 +0000 (+0100) Subject: Use `min`/`max` macros in a few more places X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=79510d81d87488062c41a27279aaf0815c7933bc;p=emacs.git Use `min`/`max` macros in a few more places * src/bidi.c (bidi_set_sos_type): * src/coding.c (consume_chars): * src/dosfns.c (dos_memory_info): * src/emacs.c (sort_args): * src/insdel.c (count_combining_before) (count_combining_after, replace_range, del_range_2): * src/sort.c (tim_sort): * src/w32.c (sys_write): * src/xfaces.c (face_at_buffer_position) (face_for_overlay_string): Prefer using 'min' and 'max' macros. --- diff --git a/src/bidi.c b/src/bidi.c index 93bb061ac32..a2b5054cb60 100644 --- a/src/bidi.c +++ b/src/bidi.c @@ -420,7 +420,7 @@ bidi_paired_bracket_type (int c) static void bidi_set_sos_type (struct bidi_it *bidi_it, int level_before, int level_after) { - int higher_level = (level_before > level_after ? level_before : level_after); + int higher_level = max (level_before, level_after); /* FIXME: should the default sos direction be user selectable? */ bidi_it->sos = ((higher_level & 1) != 0 ? R2L : L2R); /* X10 */ diff --git a/src/coding.c b/src/coding.c index 219e3554c18..a5bec8b6305 100644 --- a/src/coding.c +++ b/src/coding.c @@ -7658,8 +7658,7 @@ consume_chars (struct coding_system *coding, Lisp_Object translation_table, if (pos == stop_charset) buf = handle_charset_annotation (pos, end_pos, coding, buf, &stop_charset); - stop = (stop_composition < stop_charset - ? stop_composition : stop_charset); + stop = min (stop_composition, stop_charset); } if (! multibytep) diff --git a/src/dosfns.c b/src/dosfns.c index 3eb3b34145e..96087116c19 100644 --- a/src/dosfns.c +++ b/src/dosfns.c @@ -652,10 +652,7 @@ dos_memory_info (unsigned long *totalram, unsigned long *freeram, mem2 *= 4096; /* Surely, the available memory is at least what we have physically available, right? */ - if (mem1 >= mem2) - freemem = mem1; - else - freemem = mem2; + freemem = max (mem1, mem2); *freeram = freemem; *totalswap = ((long)info.max_pages_in_paging_file == -1L) diff --git a/src/emacs.c b/src/emacs.c index eb1871841ec..97c65fbfd33 100644 --- a/src/emacs.c +++ b/src/emacs.c @@ -2900,7 +2900,7 @@ sort_args (int argc, char **argv) new[to++] = argv[best + i + 1]; } - incoming_used += 1 + (options[best] > 0 ? options[best] : 0); + incoming_used += 1 + max (options[best], 0); /* Clear out this option in ARGV. */ argv[best] = 0; diff --git a/src/insdel.c b/src/insdel.c index e41d9945551..3809f8bc060 100644 --- a/src/insdel.c +++ b/src/insdel.c @@ -803,7 +803,7 @@ count_combining_before (const unsigned char *string, ptrdiff_t length, while (!CHAR_HEAD_P (*p) && p < string + length) p++; - return (combining_bytes < p - string ? combining_bytes : p - string); + return min (combining_bytes, p - string); } /* See if the bytes after POS/POS_BYTE combine with bytes @@ -865,7 +865,7 @@ count_combining_after (const unsigned char *string, bufp++, pos_byte++; while (!CHAR_HEAD_P (*bufp)) bufp++, pos_byte++; - return (bytes <= pos_byte - opos_byte ? bytes : pos_byte - opos_byte); + return min (bytes, pos_byte - opos_byte); } #endif @@ -1568,9 +1568,8 @@ replace_range (ptrdiff_t from, ptrdiff_t to, Lisp_Object new, /* Relocate point as if it were a marker. */ if (from < PT) - adjust_point ((from + inschars - (PT < to ? PT : to)), - (from_byte + outgoing_insbytes - - (PT_BYTE < to_byte ? PT_BYTE : to_byte))); + adjust_point ((from + inschars - min (PT, to)), + (from_byte + outgoing_insbytes - min (PT_BYTE, to_byte))); check_markers (); @@ -1919,8 +1918,8 @@ del_range_2 (ptrdiff_t from, ptrdiff_t from_byte, /* Relocate point as if it were a marker. */ if (from < PT) - adjust_point (from - (PT < to ? PT : to), - from_byte - (PT_BYTE < to_byte ? PT_BYTE : to_byte)); + adjust_point (from - min (PT, to), + from_byte - min (PT_BYTE, to_byte)); offset_intervals (current_buffer, from, - nchars_del); diff --git a/src/sort.c b/src/sort.c index 5f7a1ee2f53..2f98bfa648c 100644 --- a/src/sort.c +++ b/src/sort.c @@ -946,8 +946,7 @@ tim_sort (Lisp_Object predicate, Lisp_Object *seq, const ptrdiff_t length) /* If the run is short, extend it to min(minrun, nremaining). */ if (n < minrun) { - const ptrdiff_t force = nremaining <= minrun ? - nremaining : minrun; + const ptrdiff_t force = min (nremaining, minrun); binarysort (&ms, lo, lo + force, lo + n); n = force; } diff --git a/src/w32.c b/src/w32.c index f365616db2b..df5465c2135 100644 --- a/src/w32.c +++ b/src/w32.c @@ -9414,7 +9414,7 @@ sys_write (int fd, const void * buffer, unsigned int count) errno = 0; while (count > 0) { - unsigned this_chunk = count < chunk ? count : chunk; + unsigned this_chunk = min (count, chunk); int n = _write (fd, p, this_chunk); if (n > 0) diff --git a/src/xfaces.c b/src/xfaces.c index e30c2fac70c..c9ade2769bd 100644 --- a/src/xfaces.c +++ b/src/xfaces.c @@ -6646,7 +6646,7 @@ face_at_buffer_position (struct window *w, ptrdiff_t pos, /* Get the `face' or `mouse_face' text property at POS, and determine the next position at which the property changes. */ prop = Fget_text_property (position, propname, w->contents); - XSETFASTINT (limit1, (limit < endpos ? limit : endpos)); + XSETFASTINT (limit1, min (limit, endpos)); end = Fnext_single_property_change (position, propname, w->contents, limit1); if (FIXNUMP (end)) endpos = XFIXNUM (end); @@ -6782,7 +6782,7 @@ face_for_overlay_string (struct window *w, ptrdiff_t pos, /* Get the `face' or `mouse_face' text property at POS, and determine the next position at which the property changes. */ prop = Fget_text_property (position, propname, w->contents); - XSETFASTINT (limit1, (limit < endpos ? limit : endpos)); + XSETFASTINT (limit1, min (limit, endpos)); end = Fnext_single_property_change (position, propname, w->contents, limit1); if (FIXNUMP (end)) endpos = XFIXNUM (end);