From f7669c1e2419b6e0152dc928f29683dde5a36ce2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Fri, 1 Jan 2021 21:56:53 +0100 Subject: [PATCH] box-drawing: quadrants: convert quad_*() macros to functions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reduces the size of the foot binary by ~4K; all the quad macros called ceil() and floor() twice per macro, which caused many float -> int -> float conversions in the expanded code. By using functions instead, there’s no expansion - the conversion only happens in one (well, four) places. --- box-drawing.c | 69 ++++++++++++++++++++++++++++++++------------------- 1 file changed, 44 insertions(+), 25 deletions(-) diff --git a/box-drawing.c b/box-drawing.c index 87da54d6..13bc0eda 100644 --- a/box-drawing.c +++ b/box-drawing.c @@ -114,11 +114,6 @@ _rect(struct buf *buf, int x1, int y1, int x2, int y2) #define vline_middle_up(thick) _vline_middle_up(thick, thick) #define vline_middle_down(thick) _vline_middle_down(thick, thick) -#define quad_upper_left() rect(0, 0, ceil(buf->width / 2.), ceil(buf->height / 2.)) -#define quad_upper_right() rect(floor(buf->width / 2.), 0, buf->width, ceil(buf->height / 2.)) -#define quad_lower_left() rect(0, floor(buf->height / 2.), ceil(buf->width / 2.), buf->height) -#define quad_lower_right() rect(floor(buf->width / 2.), floor(buf->height / 2.), buf->width, buf->height) - static void draw_box_drawings_light_horizontal(struct buf *buf) { @@ -1627,74 +1622,98 @@ draw_right_one_eighth_block(struct buf *buf) rect(buf->width - round(buf->width / 8.), 0, buf->width, buf->height); } +static void +quad_upper_left(struct buf *buf) +{ + rect(0, 0, ceil(buf->width / 2.), ceil(buf->height / 2.)); +} + +static void +quad_upper_right(struct buf *buf) +{ + rect(floor(buf->width / 2.), 0, buf->width, ceil(buf->height / 2.)); +} + +static void +quad_lower_left(struct buf *buf) +{ + rect(0, floor(buf->height / 2.), ceil(buf->width / 2.), buf->height); +} + +static void +quad_lower_right(struct buf *buf) +{ + rect(floor(buf->width / 2.), floor(buf->height / 2.), buf->width, buf->height); +} + static void draw_quadrant_lower_left(struct buf *buf) { - quad_lower_left(); + quad_lower_left(buf); } static void draw_quadrant_lower_right(struct buf *buf) { - quad_lower_right(); + quad_lower_right(buf); } static void draw_quadrant_upper_left(struct buf *buf) { - quad_upper_left(); + quad_upper_left(buf); } static void draw_quadrant_upper_left_and_lower_left_and_lower_right(struct buf *buf) { - quad_upper_left(); - quad_lower_left(); - quad_lower_right(); + quad_upper_left(buf); + quad_lower_left(buf); + quad_lower_right(buf); } static void draw_quadrant_upper_left_and_lower_right(struct buf *buf) { - quad_upper_left(); - quad_lower_right(); + quad_upper_left(buf); + quad_lower_right(buf); } static void draw_quadrant_upper_left_and_upper_right_and_lower_left(struct buf *buf) { - quad_upper_left(); - quad_upper_right(); - quad_lower_left(); + quad_upper_left(buf); + quad_upper_right(buf); + quad_lower_left(buf); } static void draw_quadrant_upper_left_and_upper_right_and_lower_right(struct buf *buf) { - quad_upper_left(); - quad_upper_right(); - quad_lower_right(); + quad_upper_left(buf); + quad_upper_right(buf); + quad_lower_right(buf); } static void draw_quadrant_upper_right(struct buf *buf) { - quad_upper_right(); + quad_upper_right(buf); } static void draw_quadrant_upper_right_and_lower_left(struct buf *buf) { - quad_upper_right(); - quad_lower_left(); + quad_upper_right(buf); + quad_lower_left(buf); } static void draw_quadrant_upper_right_and_lower_left_and_lower_right(struct buf *buf) { - quad_upper_right(); - quad_lower_left(); - quad_lower_right(); + quad_upper_right(buf); + quad_lower_left(buf); + quad_lower_right(buf); } #define sextant_upper_left() rect(0, 0, round(buf->width / 2.), round(buf->height / 3.))