From 513bf031a589d9e2a1a2730adf56f95e5e316a06 Mon Sep 17 00:00:00 2001 From: Berke Güzel Date: Wed, 14 Oct 2026 17:17:43 +0300 Subject: Remove unused private functions and inline trivial helpers --- src/palette.c | 45 ++++++++++----------------------------------- 1 file changed, 10 insertions(+), 35 deletions(-) (limited to 'src/palette.c') diff --git a/src/palette.c b/src/palette.c index bfaba6c..cee5bad 100644 --- a/src/palette.c +++ b/src/palette.c @@ -245,25 +245,6 @@ static bool parse_fraction(const char *s, size_t len, uint8_t *out) return true; } -static const char *skip_leading_ws(const char *s) -{ - if (*s != ' ' && *s != '\t') - return s; - while (*s == ' ' || *s == '\t') - s++; - return s; -} - -static size_t rtrimmed_len(const char *s) -{ - size_t n = strlen(s); - if (n == 0 || (s[n - 1] != ' ' && s[n - 1] != '\t')) - return n; - while (n > 0 && (s[n - 1] == ' ' || s[n - 1] == '\t')) - n--; - return n; -} - static bool parse_hex_rgb(const char *s, size_t cw, uint32_t *out) { uint8_t r, g, b; @@ -279,8 +260,12 @@ bool term_color_parse(const char *input, uint32_t *out) { if (!input || !out) return false; - const char *s = skip_leading_ws(input); - size_t len = rtrimmed_len(s); + const char *s = input; + while (*s == ' ' || *s == '\t') + s++; + size_t len = strlen(s); + while (len > 0 && (s[len - 1] == ' ' || s[len - 1] == '\t')) + len--; if (len == 0) return false; @@ -466,15 +451,10 @@ static void derive_palette(uint32_t *p, const struct term_theme *theme) } } -static bool theme_is_zero(const struct term_theme *theme) -{ - static const struct term_theme zero; - return !memcmp(theme, &zero, sizeof(zero)); -} - void term_palette_init(struct palette *p, const struct term_theme *theme) { - p->theme = theme && !theme_is_zero(theme) ? *theme : builtin_theme; + static const struct term_theme zero; + p->theme = theme && memcmp(theme, &zero, sizeof(zero)) ? *theme : builtin_theme; if (!p->theme.cursor) p->theme.cursor = builtin_theme.cursor; derive_palette(p->base, &p->theme); @@ -482,14 +462,9 @@ void term_palette_init(struct palette *p, const struct term_theme *theme) p->version++; } -static bool valid_slot(int slot) -{ - return slot >= 0 && slot < TERM_PALETTE_SIZE; -} - void term_palette_set(struct palette *p, int slot, uint32_t argb) { - if (!valid_slot(slot) || p->colors[slot] == argb) + if ((unsigned)slot >= TERM_PALETTE_SIZE || p->colors[slot] == argb) return; p->colors[slot] = argb; p->version++; @@ -497,7 +472,7 @@ void term_palette_set(struct palette *p, int slot, uint32_t argb) void term_palette_reset(struct palette *p, int slot) { - if (valid_slot(slot)) + if ((unsigned)slot < TERM_PALETTE_SIZE) term_palette_set(p, slot, p->base[slot]); } -- cgit v1.2.3