diff options
author | Tavian Barnes <tavianator@tavianator.com> | 2024-06-05 12:33:43 -0400 |
---|---|---|
committer | Tavian Barnes <tavianator@tavianator.com> | 2024-06-05 12:35:22 -0400 |
commit | cb6314ba9b1c1c017aa686ea6dfdf733939aaa1b (patch) | |
tree | 296dcae30e39670ba3fdb7e0f0259605225b23a2 /src/printf.c | |
parent | a39904098ff9e022bc755f36a9546cbf07a3ff49 (diff) | |
download | bfs-cb6314ba9b1c1c017aa686ea6dfdf733939aaa1b.tar.xz |
Replace some switch-case lookups with arrays
Diffstat (limited to 'src/printf.c')
-rw-r--r-- | src/printf.c | 43 |
1 files changed, 19 insertions, 24 deletions
diff --git a/src/printf.c b/src/printf.c index f514361..6b07c54 100644 --- a/src/printf.c +++ b/src/printf.c @@ -505,30 +505,25 @@ static int bfs_printf_u(CFILE *cfile, const struct bfs_fmt *fmt, const struct BF } static const char *bfs_printf_type(enum bfs_type type) { - switch (type) { - case BFS_BLK: - return "b"; - case BFS_CHR: - return "c"; - case BFS_DIR: - return "d"; - case BFS_DOOR: - return "D"; - case BFS_FIFO: - return "p"; - case BFS_LNK: - return "l"; - case BFS_PORT: - return "P"; - case BFS_REG: - return "f"; - case BFS_SOCK: - return "s"; - case BFS_WHT: - return "w"; - default: - return "U"; - } + const char *const names[] = { + [BFS_BLK] = "b", + [BFS_CHR] = "c", + [BFS_DIR] = "d", + [BFS_DOOR] = "D", + [BFS_FIFO] = "p", + [BFS_LNK] = "l", + [BFS_PORT] = "P", + [BFS_REG] = "f", + [BFS_SOCK] = "s", + [BFS_WHT] = "w", + }; + + const char *name = NULL; + if ((size_t)type < countof(names)) { + name = names[type]; + } + + return name ? name : "U"; } /** %y: type */ |