From 66497cfd4d9e6c28d0d5678da51812e76b482da7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Sat, 2 Jan 2021 12:08:32 +0100 Subject: [PATCH] box-drawing: LIGHT ARC: use min/max instead of checking range inside loop --- box-drawing.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/box-drawing.c b/box-drawing.c index 8b7c35f5..31e33528 100644 --- a/box-drawing.c +++ b/box-drawing.c @@ -1275,16 +1275,11 @@ draw_box_drawings_light_arc(wchar_t wc, struct buf *buf) assert(row_end > row_start); assert(col_end > col_start); - for (int r = row_start; r < row_end; r++) { - if (r < 0 || r >= buf->height) - continue; - - for (int c = col_start; c < col_end; c++) { - if (c >= 0 && c < buf->width) { - size_t idx = c / 8; - size_t bit_no = c % 8; - buf->data[r * buf->stride + idx] |= 1 << bit_no; - } + for (int r = max(row_start, 0); r < min(row_end, buf->height); r++) { + for (int c = max(col_start, 0); c < min(col_end, buf->width); c++) { + size_t idx = c / 8; + size_t bit_no = c % 8; + buf->data[r * buf->stride + idx] |= 1 << bit_no; } } }