diff options
author | Felipe Oliveira Carvalho <felipekde@gmail.com> | 2014-12-13 10:55:51 -0300 |
---|---|---|
committer | Felipe Oliveira Carvalho <felipekde@gmail.com> | 2014-12-13 23:36:11 -0300 |
commit | 77135447e09903b45d1482da45869946212f7904 (patch) | |
tree | 53b17c11d4bfbe8031842cfb65ae5c53c5eb41d7 /src/nvim/hashtab.c | |
parent | 64a32d55c59188f1e922ca438fdb2d65caa06665 (diff) | |
download | rneovim-77135447e09903b45d1482da45869946212f7904.tar.gz rneovim-77135447e09903b45d1482da45869946212f7904.tar.bz2 rneovim-77135447e09903b45d1482da45869946212f7904.zip |
Reduce indentation level by early returning or continuing loop
Replace code like this
```c
func() {
if (cond) {
...
...
...
}
return ret;
}
```
```c
for (...) {
if (cond) {
...
...
...
}
}
```
with
```c
func() {
if (!cond) {
return ret;
}
...
...
...
}
```
```c
for (...) {
if (!cond) {
continue;
}
...
...
...
}
```
Diffstat (limited to 'src/nvim/hashtab.c')
-rw-r--r-- | src/nvim/hashtab.c | 31 |
1 files changed, 16 insertions, 15 deletions
diff --git a/src/nvim/hashtab.c b/src/nvim/hashtab.c index 5b0dc508fa..6b90c4fee4 100644 --- a/src/nvim/hashtab.c +++ b/src/nvim/hashtab.c @@ -329,24 +329,25 @@ static void hash_may_resize(hashtab_T *ht, size_t minitems) size_t todo = ht->ht_used; for (hashitem_T *olditem = oldarray; todo > 0; ++olditem) { - if (!HASHITEM_EMPTY(olditem)) { - // The algorithm to find the spot to add the item is identical to - // the algorithm to find an item in hash_lookup(). But we only - // need to search for a NULL key, thus it's simpler. - hash_T newi = olditem->hi_hash & newmask; - hashitem_T *newitem = &newarray[newi]; - if (newitem->hi_key != NULL) { - for (hash_T perturb = olditem->hi_hash;; perturb >>= PERTURB_SHIFT) { - newi = 5 * newi + perturb + 1; - newitem = &newarray[newi & newmask]; - if (newitem->hi_key == NULL) { - break; - } + if (HASHITEM_EMPTY(olditem)) { + continue; + } + // The algorithm to find the spot to add the item is identical to + // the algorithm to find an item in hash_lookup(). But we only + // need to search for a NULL key, thus it's simpler. + hash_T newi = olditem->hi_hash & newmask; + hashitem_T *newitem = &newarray[newi]; + if (newitem->hi_key != NULL) { + for (hash_T perturb = olditem->hi_hash;; perturb >>= PERTURB_SHIFT) { + newi = 5 * newi + perturb + 1; + newitem = &newarray[newi & newmask]; + if (newitem->hi_key == NULL) { + break; } } - *newitem = *olditem; - todo--; } + *newitem = *olditem; + todo--; } if (ht->ht_array != ht->ht_smallarray) { |