diff options
author | Yegappan Lakshmanan <yegappan@yahoo.com> | 2023-01-09 19:04:23 +0000 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2023-01-09 19:04:23 +0000 |
commit | 1cfb14aa972ccf3235ac67f07b7db1175b7c5384 (patch) | |
tree | b746eda548993b9e0987d7c9c0c543ddddc5758f /src/dict.c | |
parent | 765d82a657c5e42d5d7c88ae410e53f398c34c43 (diff) |
patch 9.0.1166: code is indented more than necessaryv9.0.1166
Problem: Code is indented more than necessary.
Solution: Use an early return where it makes sense. (Yegappan Lakshmanan,
closes #11792)
Diffstat (limited to 'src/dict.c')
-rw-r--r-- | src/dict.c | 130 |
1 files changed, 65 insertions, 65 deletions
diff --git a/src/dict.c b/src/dict.c index d45fcff0ab..6941845cda 100644 --- a/src/dict.c +++ b/src/dict.c @@ -30,21 +30,21 @@ dict_alloc(void) dict_T *d; d = ALLOC_CLEAR_ONE(dict_T); - if (d != NULL) - { - // Add the dict to the list of dicts for garbage collection. - if (first_dict != NULL) - first_dict->dv_used_prev = d; - d->dv_used_next = first_dict; - d->dv_used_prev = NULL; - first_dict = d; - - hash_init(&d->dv_hashtab); - d->dv_lock = 0; - d->dv_scope = 0; - d->dv_refcount = 0; - d->dv_copyID = 0; - } + if (d == NULL) + return NULL; + + // Add the dict to the list of dicts for garbage collection. + if (first_dict != NULL) + first_dict->dv_used_prev = d; + d->dv_used_next = first_dict; + d->dv_used_prev = NULL; + first_dict = d; + + hash_init(&d->dv_hashtab); + d->dv_lock = 0; + d->dv_scope = 0; + d->dv_refcount = 0; + d->dv_copyID = 0; return d; } @@ -228,13 +228,13 @@ dictitem_alloc(char_u *key) size_t len = STRLEN(key); di = alloc(offsetof(dictitem_T, di_key) + len + 1); - if (di != NULL) - { - mch_memmove(di->di_key, key, len + 1); - di->di_flags = DI_FLAGS_ALLOC; - di->di_tv.v_lock = 0; - di->di_tv.v_type = VAR_UNKNOWN; - } + if (di == NULL) + return NULL; + + mch_memmove(di->di_key, key, len + 1); + di->di_flags = DI_FLAGS_ALLOC; + di->di_tv.v_lock = 0; + di->di_tv.v_type = VAR_UNKNOWN; return di; } @@ -248,12 +248,12 @@ dictitem_copy(dictitem_T *org) size_t len = STRLEN(org->di_key); di = alloc(offsetof(dictitem_T, di_key) + len + 1); - if (di != NULL) - { - mch_memmove(di->di_key, org->di_key, len + 1); - di->di_flags = DI_FLAGS_ALLOC; - copy_tv(&org->di_tv, &di->di_tv); - } + if (di == NULL) + return NULL; + + mch_memmove(di->di_key, org->di_key, len + 1); + di->di_flags = DI_FLAGS_ALLOC; + copy_tv(&org->di_tv, &di->di_tv); return di; } @@ -303,53 +303,53 @@ dict_copy(dict_T *orig, int deep, int top, int copyID) return NULL; copy = dict_alloc(); - if (copy != NULL) + if (copy == NULL) + return NULL; + + if (copyID != 0) { - if (copyID != 0) - { - orig->dv_copyID = copyID; - orig->dv_copydict = copy; - } - if (orig->dv_type == NULL || top || deep) - copy->dv_type = NULL; - else - copy->dv_type = alloc_type(orig->dv_type); + orig->dv_copyID = copyID; + orig->dv_copydict = copy; + } + if (orig->dv_type == NULL || top || deep) + copy->dv_type = NULL; + else + copy->dv_type = alloc_type(orig->dv_type); - todo = (int)orig->dv_hashtab.ht_used; - for (hi = orig->dv_hashtab.ht_array; todo > 0 && !got_int; ++hi) + todo = (int)orig->dv_hashtab.ht_used; + for (hi = orig->dv_hashtab.ht_array; todo > 0 && !got_int; ++hi) + { + if (!HASHITEM_EMPTY(hi)) { - if (!HASHITEM_EMPTY(hi)) - { - --todo; + --todo; - di = dictitem_alloc(hi->hi_key); - if (di == NULL) - break; - if (deep) - { - if (item_copy(&HI2DI(hi)->di_tv, &di->di_tv, - deep, FALSE, copyID) == FAIL) - { - vim_free(di); - break; - } - } - else - copy_tv(&HI2DI(hi)->di_tv, &di->di_tv); - if (dict_add(copy, di) == FAIL) + di = dictitem_alloc(hi->hi_key); + if (di == NULL) + break; + if (deep) + { + if (item_copy(&HI2DI(hi)->di_tv, &di->di_tv, + deep, FALSE, copyID) == FAIL) { - dictitem_free(di); + vim_free(di); break; } } + else + copy_tv(&HI2DI(hi)->di_tv, &di->di_tv); + if (dict_add(copy, di) == FAIL) + { + dictitem_free(di); + break; + } } + } - ++copy->dv_refcount; - if (todo > 0) - { - dict_unref(copy); - copy = NULL; - } + ++copy->dv_refcount; + if (todo > 0) + { + dict_unref(copy); + copy = NULL; } return copy; |