aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/hashtab.c
diff options
context:
space:
mode:
authorLewis Russell <lewis6991@gmail.com>2024-07-19 11:00:13 +0100
committerLewis Russell <me@lewisr.dev>2024-07-30 22:43:29 +0100
commitd1bd3d643e5846eee7343ba1a12bdcbbc8cee7b0 (patch)
treeca5a4a60fca9e814d0a3937cc4ff21ed9e037520 /src/nvim/hashtab.c
parent1b5a394ffd4bb638ec9cbbb5e4d12d11225389cf (diff)
downloadrneovim-d1bd3d643e5846eee7343ba1a12bdcbbc8cee7b0.tar.gz
rneovim-d1bd3d643e5846eee7343ba1a12bdcbbc8cee7b0.tar.bz2
rneovim-d1bd3d643e5846eee7343ba1a12bdcbbc8cee7b0.zip
refactor: collapse statements in single assignments
Problem: Variables are often assigned multiple places in common patterns. Solution: Replace these common patterns with different patterns that reduce the number of assignments. Use `MAX` and `MIN`: ```c if (x < y) { x = y; } // --> x = MAX(x, y); ``` ```c if (x > y) { x = y; } // --> x = MIN(x, y); ``` Use ternary: ```c int a; if (cond) { a = b; } els { a = c; } // --> int a = cond ? b : c; ```
Diffstat (limited to 'src/nvim/hashtab.c')
-rw-r--r--src/nvim/hashtab.c5
1 files changed, 1 insertions, 4 deletions
diff --git a/src/nvim/hashtab.c b/src/nvim/hashtab.c
index a8a998a361..95df5e5383 100644
--- a/src/nvim/hashtab.c
+++ b/src/nvim/hashtab.c
@@ -316,10 +316,7 @@ static void hash_may_resize(hashtab_T *ht, size_t minitems)
}
} else {
// Use specified size.
- if (minitems < ht->ht_used) {
- // just in case...
- minitems = ht->ht_used;
- }
+ minitems = MAX(minitems, ht->ht_used);
// array is up to 2/3 full
minsize = minitems * 3 / 2;
}