diff options
author | Tavian Barnes <tavianator@tavianator.com> | 2025-02-05 13:29:05 -0500 |
---|---|---|
committer | Tavian Barnes <tavianator@tavianator.com> | 2025-02-06 10:38:45 -0500 |
commit | a85565334708840dd44b849a91c1fa09b9038093 (patch) | |
tree | 29599824ab1f5ef02713e558bc68c7f3388c32c8 /src/color.c | |
parent | f8aca1c316b116c2de11d42010fdda0ddb418750 (diff) | |
download | bfs-a85565334708840dd44b849a91c1fa09b9038093.tar.xz |
trie: New trie_{get,set}_{str,mem}() functions
Diffstat (limited to 'src/color.c')
-rw-r--r-- | src/color.c | 19 |
1 files changed, 3 insertions, 16 deletions
diff --git a/src/color.c b/src/color.c index fdaf2eb..0cc950b 100644 --- a/src/color.c +++ b/src/color.c @@ -143,13 +143,7 @@ static int init_esc(struct colors *colors, const char *name, const char *value, *field = esc; - struct trie_leaf *leaf = trie_insert_str(&colors->names, name); - if (!leaf) { - return -1; - } - - leaf->value = field; - return 0; + return trie_set_str(&colors->names, name, field); } /** Check if an escape sequence is equal to a string. */ @@ -159,8 +153,7 @@ static bool esc_eq(const struct esc_seq *esc, const char *str, size_t len) { /** Get an escape sequence from the table. */ static struct esc_seq **get_esc(const struct colors *colors, const char *name) { - const struct trie_leaf *leaf = trie_find_str(&colors->names, name); - return leaf ? leaf->value : NULL; + return trie_get_str(&colors->names, name); } /** Append an escape sequence to a string. */ @@ -225,13 +218,7 @@ static int insert_ext(struct trie *trie, struct ext_color *ext) { } size_t len = ext->len + 1; - leaf = trie_insert_mem(trie, ext->ext, len); - if (!leaf) { - return -1; - } - - leaf->value = ext; - return 0; + return trie_set_mem(trie, ext->ext, len, ext); } /** Set the color for an extension. */ |