From 065b905fe05283820bb68d56c4057bd2c8484fc1 Mon Sep 17 00:00:00 2001 From: Randy Palamar Date: Sun, 23 Nov 2025 20:36:44 -0700 Subject: text-util: convert trivial functions to macros This would be less of an issue if vis was compiled as a single translation unit but even then compiler may not inline them if they are not marked as static. --- text-util.c | 12 ------------ text-util.h | 6 +++--- 2 files changed, 3 insertions(+), 15 deletions(-) diff --git a/text-util.c b/text-util.c index 3cc994e..7e47cce 100644 --- a/text-util.c +++ b/text-util.c @@ -4,18 +4,6 @@ #include #include -bool text_range_valid(const Filerange *r) { - return r->start != EPOS && r->end != EPOS && r->start <= r->end; -} - -size_t text_range_size(const Filerange *r) { - return text_range_valid(r) ? r->end - r->start : 0; -} - -Filerange text_range_empty(void) { - return (Filerange){ .start = EPOS, .end = EPOS }; -} - Filerange text_range_union(const Filerange *r1, const Filerange *r2) { if (!text_range_valid(r1)) return *r2; diff --git a/text-util.h b/text-util.h index 709e255..85bfa04 100644 --- a/text-util.h +++ b/text-util.h @@ -6,11 +6,11 @@ #include "text.h" /* test whether the given range is valid (start <= end) */ -bool text_range_valid(const Filerange*); +#define text_range_valid(r) ((r)->start != EPOS && (r)->end != EPOS && (r)->start <= (r)->end) /* get the size of the range (end-start) or zero if invalid */ -size_t text_range_size(const Filerange*); +#define text_range_size(r) (text_range_valid(r) ? (r)->end - (r)->start : 0) /* create an empty / invalid range of size zero */ -Filerange text_range_empty(void); +#define text_range_empty() (Filerange){.start = EPOS, .end = EPOS} /* merge two ranges into a new one which contains both of them */ Filerange text_range_union(const Filerange*, const Filerange*); /* get intersection of two ranges */ -- cgit v1.2.3