A `swap` macro prevents programming errors and is more concise.
It is a natural addition to our existing `min` and `max` macros.
* src/lisp.h (swap): New macro.
* lwlib/xlwmenu.c (draw_shadow_rectangle, draw_shadow_rhombus):
* src/androidterm.c (android_get_surrounding_text):
* src/buffer.c (Fmake_overlay, modify_overlay, Fmove_overlay):
* src/dispnew.c (swap_glyphs_in_rows, reverse_rows):
* src/editfns.c (Finsert_buffer_substring)
(Fcompare_buffer_substrings):
* src/eval.c (run_hook_wrapped_funcall):
* src/fns.c (extract_data_from_object):
* src/regex-emacs.c (forall_firstchar_1):
* src/textconv.c (textconv_query, get_extracted_text)
(get_surrounding_text):
* src/textprop.c (validate_interval_range)
(verify_interval_modification):
* src/w32uniscribe.c (OTF_INT16_VAL):
* src/xfaces.c (load_face_colors):
* src/xterm.c (SWAPCARD32): Prefer using above macro to open-coding.
}
if (!erase_p && down_p)
- {
- GC temp;
- temp = top_gc;
- top_gc = bottom_gc;
- bottom_gc = temp;
- }
+ swap (top_gc, bottom_gc);
/* Do draw (or erase) shadows */
points [0].x = x;
}
if (!erase_p && down_p)
- {
- GC temp;
- temp = top_gc;
- top_gc = bottom_gc;
- bottom_gc = temp;
- }
+ swap (top_gc, bottom_gc);
points [0].x = x;
points [0].y = y + height / 2;
{
struct android_get_surrounding_text_context *request;
struct frame *f;
- ptrdiff_t temp;
request = data;
bad input methods. */
if (request->end < request->start)
- {
- temp = request->start;
- request->start = request->end;
- request->end = temp;
- }
+ swap (request->start, request->end);
/* Retrieve the conversion region. */
CHECK_FIXNUM_COERCE_MARKER (end);
if (XFIXNUM (beg) > XFIXNUM (end))
- {
- Lisp_Object temp;
- temp = beg; beg = end; end = temp;
- }
+ swap (beg, end);
ptrdiff_t obeg = clip_to_bounds (BUF_BEG (b), XFIXNUM (beg), BUF_Z (b));
ptrdiff_t oend = clip_to_bounds (obeg, XFIXNUM (end), BUF_Z (b));
modify_overlay (struct buffer *buf, ptrdiff_t start, ptrdiff_t end)
{
if (start > end)
- {
- ptrdiff_t temp = start;
- start = end;
- end = temp;
- }
+ swap (start, end);
BUF_COMPUTE_UNCHANGED (buf, start, end);
CHECK_FIXNUM_COERCE_MARKER (end);
if (XFIXNUM (beg) > XFIXNUM (end))
- {
- Lisp_Object temp;
- temp = beg; beg = end; end = temp;
- }
+ swap (beg, end);
specbind (Qinhibit_quit, Qt); /* FIXME: Why? */
int i, j;
for (i = start, j = end - 1; i < j; ++i, --j)
- {
- /* Non-ISO HP/UX compiler doesn't like auto struct
- initialization. */
- struct glyph_row temp;
- temp = matrix->rows[i];
- matrix->rows[i] = matrix->rows[j];
- matrix->rows[j] = temp;
- }
+ swap (matrix->rows[i], matrix->rows[j]);
}
static void
swap_glyphs_in_rows (struct glyph_row *a, struct glyph_row *b)
{
- int area;
-
- for (area = 0; area < LAST_AREA; ++area)
+ for (int area = 0; area < LAST_AREA; ++area)
{
/* Number of glyphs to swap. */
int max_used = max (a->used[area], b->used[area]);
while (glyph_a < glyph_a_end)
{
- /* Non-ISO HP/UX compiler doesn't like auto struct
- initialization. */
- struct glyph temp;
- temp = *glyph_a;
- *glyph_a = *glyph_b;
- *glyph_b = temp;
+ swap (*glyph_a, *glyph_b);
++glyph_a;
++glyph_b;
}
using `string-make-multibyte' or `string-make-unibyte', which see. */)
(Lisp_Object buffer, Lisp_Object start, Lisp_Object end)
{
- register EMACS_INT b, e, temp;
+ register EMACS_INT b, e;
register struct buffer *bp, *obuf;
Lisp_Object buf;
b = !NILP (start) ? fix_position (start) : BUF_BEGV (bp);
e = !NILP (end) ? fix_position (end) : BUF_ZV (bp);
if (b > e)
- temp = b, b = e, e = temp;
+ swap (b, e);
if (!(BUF_BEGV (bp) <= b && e <= BUF_ZV (bp)))
args_out_of_range (start, end);
determines whether case is significant or ignored. */)
(Lisp_Object buffer1, Lisp_Object start1, Lisp_Object end1, Lisp_Object buffer2, Lisp_Object start2, Lisp_Object end2)
{
- register EMACS_INT begp1, endp1, begp2, endp2, temp;
+ register EMACS_INT begp1, endp1, begp2, endp2;
register struct buffer *bp1, *bp2;
register Lisp_Object trt
= (!NILP (Vcase_fold_search)
begp1 = !NILP (start1) ? fix_position (start1) : BUF_BEGV (bp1);
endp1 = !NILP (end1) ? fix_position (end1) : BUF_ZV (bp1);
if (begp1 > endp1)
- temp = begp1, begp1 = endp1, endp1 = temp;
+ swap (begp1, endp1);
if (!(BUF_BEGV (bp1) <= begp1
&& begp1 <= endp1
begp2 = !NILP (start2) ? fix_position (start2) : BUF_BEGV (bp2);
endp2 = !NILP (end2) ? fix_position (end2) : BUF_ZV (bp2);
if (begp2 > endp2)
- temp = begp2, begp2 = endp2, endp2 = temp;
+ swap (begp2, endp2);
if (!(BUF_BEGV (bp2) <= begp2
&& begp2 <= endp2
static Lisp_Object
run_hook_wrapped_funcall (ptrdiff_t nargs, Lisp_Object *args)
{
- Lisp_Object tmp = args[0], ret;
- args[0] = args[1];
- args[1] = tmp;
- ret = Ffuncall (nargs, args);
- args[1] = args[0];
- args[0] = tmp;
+ swap (args[0], args[1]);
+ Lisp_Object ret = Ffuncall (nargs, args);
+ swap (args[1], args[0]);
return ret;
}
b = !NILP (start) ? fix_position (start) : BEGV;
e = !NILP (end) ? fix_position (end) : ZV;
if (b > e)
- {
- EMACS_INT temp = b;
- b = e;
- e = temp;
- }
+ swap (b, e);
if (!(BEGV <= b && e <= ZV))
args_out_of_range (start, end);
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))
+/* Swap values of a and b. */
+#define swap(a, b) \
+ do { typeof (a) __tmp; __tmp = (a); (a) = (b); (b) = __tmp; } while (0);
+
/* Number of elements in an array. */
#define ARRAYELTS(arr) (sizeof (arr) / sizeof (arr)[0])
while (true)
{
- re_char *newp1, *newp2, *tmp;
+ re_char *newp1, *newp2;
re_char *p_orig = p;
int offset;
/* We have to check that both destinations are safe.
Arrange for `newp1` to be the smaller of the two. */
if (newp1 > newp2)
- (tmp = newp1, newp1 = newp2, newp2 = tmp);
+ swap (newp1, newp2);
if (newp2 <= p_orig) /* Both destinations go backward! */
{
{
specpdl_ref count;
ptrdiff_t pos, pos_byte, end, end_byte, start;
- ptrdiff_t temp, temp1, mark;
+ ptrdiff_t mark;
char *buffer;
struct window *w;
if (end < pos)
{
eassert (end_byte < pos_byte);
- temp = pos_byte;
- temp1 = pos;
- pos_byte = end_byte;
- pos = end;
- end = temp1;
- end_byte = temp;
+ swap (pos_byte, end_byte);
+ swap (pos, end);
}
/* Return the string first. */
start = marker_position (BVAR (current_buffer, mark));
end = PT;
- /* Sort start and end. start_byte is used to hold a
- temporary value. */
-
+ /* Sort start and end. */
if (start > end)
- {
- start_byte = end;
- end = start;
- start = start_byte;
- }
+ swap (start, end);
}
else
goto finish;
ptrdiff_t *end_return)
{
specpdl_ref count;
- ptrdiff_t start, end, start_byte, end_byte, mark, temp;
+ ptrdiff_t start, end, start_byte, end_byte, mark;
char *buffer;
if (!WINDOW_LIVE_P (f->old_selected_window))
/* Now sort start and end. */
if (end < start)
- {
- temp = start;
- start = end;
- end = temp;
- }
+ swap (start, end)
/* And subtract left and right. */
return NULL;
if (XFIXNUM (*begin) > XFIXNUM (*end))
- {
- Lisp_Object n;
- n = *begin;
- *begin = *end;
- *end = n;
- }
+ swap (*begin, *end);
if (BUFFERP (object))
{
return;
if (start > end)
- {
- ptrdiff_t temp = start;
- start = end;
- end = temp;
- }
+ swap (start, end);
/* For an insert operation, check the two chars around the position. */
if (start == end)
#define OTF_INT16_VAL(TABLE, OFFSET, PTR) \
do { \
- BYTE temp, data[2]; \
+ BYTE data[2]; \
if (GetFontData (context, TABLE, OFFSET, data, 2) != 2) \
goto font_table_error; \
- temp = data[0], data[0] = data[1], data[1] = temp; \
+ swap (data[0], data[1]); \
memcpy (PTR, data, 2); \
} while (0)
/* Swap colors if face is inverse-video. */
if (EQ (attrs[LFACE_INVERSE_INDEX], Qt))
- {
- Lisp_Object tmp;
- tmp = fg;
- fg = bg;
- bg = tmp;
- }
+ swap (fg, bg);
/* Check for support for foreground, not for background because
face_color_supported_p is smart enough to know that grays are
#define SWAPCARD32(l) \
{ \
struct { unsigned t : 32; } bit32; \
- char n, *tp = (char *) &bit32; \
+ char *tp = (char *) &bit32; \
bit32.t = l; \
- n = tp[0]; tp[0] = tp[3]; tp[3] = n; \
- n = tp[1]; tp[1] = tp[2]; tp[2] = n; \
+ swap (tp[0], tp[3]); \
+ swap (tp[1], tp[2]); \
l = bit32.t; \
}
#define SWAPCARD16(s) \
{ \
struct { unsigned t : 16; } bit16; \
- char n, *tp = (char *) &bit16; \
+ char *tp = (char *) &bit16; \
bit16.t = s; \
- n = tp[0]; tp[0] = tp[1]; tp[1] = n; \
+ swap (tp[0], tp[1]); \
s = bit16.t; \
}