Skip to content

Commit 142ed77

Browse files
yegappanbrammool
authored andcommitted
patch 9.0.1246: code is indented more than necessary
Problem: Code is indented more than necessary. Solution: Use an early return where it makes sense. (Yegappan Lakshmanan, closes #11887)
1 parent 032713f commit 142ed77

13 files changed

Lines changed: 505 additions & 510 deletions

src/ui.c

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -83,20 +83,20 @@ ui_inchar_undo(char_u *s, int len)
8383
if (ta_str != NULL)
8484
newlen += ta_len - ta_off;
8585
new = alloc(newlen);
86-
if (new != NULL)
86+
if (new == NULL)
87+
return;
88+
89+
if (ta_str != NULL)
8790
{
88-
if (ta_str != NULL)
89-
{
90-
mch_memmove(new, ta_str + ta_off, (size_t)(ta_len - ta_off));
91-
mch_memmove(new + ta_len - ta_off, s, (size_t)len);
92-
vim_free(ta_str);
93-
}
94-
else
95-
mch_memmove(new, s, (size_t)len);
96-
ta_str = new;
97-
ta_len = newlen;
98-
ta_off = 0;
91+
mch_memmove(new, ta_str + ta_off, (size_t)(ta_len - ta_off));
92+
mch_memmove(new + ta_len - ta_off, s, (size_t)len);
93+
vim_free(ta_str);
9994
}
95+
else
96+
mch_memmove(new, s, (size_t)len);
97+
ta_str = new;
98+
ta_len = newlen;
99+
ta_off = 0;
100100
}
101101
#endif
102102

@@ -815,25 +815,25 @@ set_input_buf(char_u *p, int overwrite)
815815
{
816816
garray_T *gap = (garray_T *)p;
817817

818-
if (gap != NULL)
818+
if (gap == NULL)
819+
return;
820+
821+
if (gap->ga_data != NULL)
819822
{
820-
if (gap->ga_data != NULL)
823+
if (overwrite || inbufcount + gap->ga_len >= INBUFLEN)
821824
{
822-
if (overwrite || inbufcount + gap->ga_len >= INBUFLEN)
823-
{
824-
mch_memmove(inbuf, gap->ga_data, gap->ga_len);
825-
inbufcount = gap->ga_len;
826-
}
827-
else
828-
{
829-
mch_memmove(inbuf + gap->ga_len, inbuf, inbufcount);
830-
mch_memmove(inbuf, gap->ga_data, gap->ga_len);
831-
inbufcount += gap->ga_len;
832-
}
833-
vim_free(gap->ga_data);
825+
mch_memmove(inbuf, gap->ga_data, gap->ga_len);
826+
inbufcount = gap->ga_len;
827+
}
828+
else
829+
{
830+
mch_memmove(inbuf + gap->ga_len, inbuf, inbufcount);
831+
mch_memmove(inbuf, gap->ga_data, gap->ga_len);
832+
inbufcount += gap->ga_len;
834833
}
835-
vim_free(gap);
834+
vim_free(gap->ga_data);
836835
}
836+
vim_free(gap);
837837
}
838838

839839
/*

src/undo.c

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1164,21 +1164,21 @@ read_string_decrypt(bufinfo_T *bi, int len)
11641164
{
11651165
char_u *ptr = alloc(len + 1);
11661166

1167-
if (ptr != NULL)
1167+
if (ptr == NULL)
1168+
return NULL;
1169+
1170+
if (len > 0 && undo_read(bi, ptr, len) == FAIL)
11681171
{
1169-
if (len > 0 && undo_read(bi, ptr, len) == FAIL)
1170-
{
1171-
vim_free(ptr);
1172-
return NULL;
1173-
}
1174-
// In case there are text properties there already is a NUL, but
1175-
// checking for that is more expensive than just adding a dummy byte.
1176-
ptr[len] = NUL;
1172+
vim_free(ptr);
1173+
return NULL;
1174+
}
1175+
// In case there are text properties there already is a NUL, but
1176+
// checking for that is more expensive than just adding a dummy byte.
1177+
ptr[len] = NUL;
11771178
#ifdef FEAT_CRYPT
1178-
if (bi->bi_state != NULL && bi->bi_buffer == NULL)
1179-
crypt_decode_inplace(bi->bi_state, ptr, len, FALSE);
1179+
if (bi->bi_state != NULL && bi->bi_buffer == NULL)
1180+
crypt_decode_inplace(bi->bi_state, ptr, len, FALSE);
11801181
#endif
1181-
}
11821182
return ptr;
11831183
}
11841184

@@ -3510,12 +3510,12 @@ u_saveline(linenr_T lnum)
35103510
void
35113511
u_clearline(void)
35123512
{
3513-
if (curbuf->b_u_line_ptr.ul_line != NULL)
3514-
{
3515-
VIM_CLEAR(curbuf->b_u_line_ptr.ul_line);
3516-
curbuf->b_u_line_ptr.ul_len = 0;
3517-
curbuf->b_u_line_lnum = 0;
3518-
}
3513+
if (curbuf->b_u_line_ptr.ul_line == NULL)
3514+
return;
3515+
3516+
VIM_CLEAR(curbuf->b_u_line_ptr.ul_line);
3517+
curbuf->b_u_line_ptr.ul_len = 0;
3518+
curbuf->b_u_line_lnum = 0;
35193519
}
35203520

35213521
/*
@@ -3726,24 +3726,24 @@ u_undofile_reset_and_delete(buf_T *buf)
37263726
void
37273727
f_undotree(typval_T *argvars UNUSED, typval_T *rettv)
37283728
{
3729-
if (rettv_dict_alloc(rettv) == OK)
3730-
{
3731-
dict_T *dict = rettv->vval.v_dict;
3732-
list_T *list;
3729+
if (rettv_dict_alloc(rettv) == FAIL)
3730+
return;
37333731

3734-
dict_add_number(dict, "synced", (long)curbuf->b_u_synced);
3735-
dict_add_number(dict, "seq_last", curbuf->b_u_seq_last);
3736-
dict_add_number(dict, "save_last", curbuf->b_u_save_nr_last);
3737-
dict_add_number(dict, "seq_cur", curbuf->b_u_seq_cur);
3738-
dict_add_number(dict, "time_cur", (long)curbuf->b_u_time_cur);
3739-
dict_add_number(dict, "save_cur", curbuf->b_u_save_nr_cur);
3732+
dict_T *dict = rettv->vval.v_dict;
3733+
list_T *list;
37403734

3741-
list = list_alloc();
3742-
if (list != NULL)
3743-
{
3744-
u_eval_tree(curbuf->b_u_oldhead, list);
3745-
dict_add_list(dict, "entries", list);
3746-
}
3735+
dict_add_number(dict, "synced", (long)curbuf->b_u_synced);
3736+
dict_add_number(dict, "seq_last", curbuf->b_u_seq_last);
3737+
dict_add_number(dict, "save_last", curbuf->b_u_save_nr_last);
3738+
dict_add_number(dict, "seq_cur", curbuf->b_u_seq_cur);
3739+
dict_add_number(dict, "time_cur", (long)curbuf->b_u_time_cur);
3740+
dict_add_number(dict, "save_cur", curbuf->b_u_save_nr_cur);
3741+
3742+
list = list_alloc();
3743+
if (list != NULL)
3744+
{
3745+
u_eval_tree(curbuf->b_u_oldhead, list);
3746+
dict_add_list(dict, "entries", list);
37473747
}
37483748
}
37493749

src/uninstall.c

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -205,18 +205,18 @@ batfile_thisversion(char *path)
205205
int found = FALSE;
206206

207207
fd = fopen(path, "r");
208-
if (fd != NULL)
208+
if (fd == NULL)
209+
return FALSE;
210+
211+
while (fgets(line, sizeof(line), fd) != NULL)
209212
{
210-
while (fgets(line, sizeof(line), fd) != NULL)
213+
if (strncmp(line, VIMBAT_UNINSTKEY, key_len) == 0)
211214
{
212-
if (strncmp(line, VIMBAT_UNINSTKEY, key_len) == 0)
213-
{
214-
found = TRUE;
215-
break;
216-
}
215+
found = TRUE;
216+
break;
217217
}
218-
fclose(fd);
219218
}
219+
fclose(fd);
220220
return found;
221221
}
222222

@@ -261,12 +261,12 @@ remove_if_exists(char *path, char *filename)
261261
sprintf(buf, "%s\\%s", path, filename);
262262

263263
fd = fopen(buf, "r");
264-
if (fd != NULL)
265-
{
266-
fclose(fd);
267-
printf("removing %s\n", buf);
268-
remove(buf);
269-
}
264+
if (fd == NULL)
265+
return;
266+
267+
fclose(fd);
268+
printf("removing %s\n", buf);
269+
remove(buf);
270270
}
271271

272272
static void
@@ -287,21 +287,21 @@ remove_start_menu(void)
287287
int i;
288288
struct stat st;
289289

290-
if (get_shell_folder_path(path, VIM_STARTMENU))
290+
if (get_shell_folder_path(path, VIM_STARTMENU) == FAIL)
291+
return;
292+
293+
for (i = 1; i < TARGET_COUNT; ++i)
294+
remove_if_exists(path, targets[i].lnkname);
295+
remove_if_exists(path, "uninstall.lnk");
296+
remove_if_exists(path, "Help.lnk");
297+
// Win95 uses .pif, WinNT uses .lnk
298+
remove_if_exists(path, "Vim tutor.pif");
299+
remove_if_exists(path, "Vim tutor.lnk");
300+
remove_if_exists(path, "Vim online.url");
301+
if (stat(path, &st) == 0)
291302
{
292-
for (i = 1; i < TARGET_COUNT; ++i)
293-
remove_if_exists(path, targets[i].lnkname);
294-
remove_if_exists(path, "uninstall.lnk");
295-
remove_if_exists(path, "Help.lnk");
296-
// Win95 uses .pif, WinNT uses .lnk
297-
remove_if_exists(path, "Vim tutor.pif");
298-
remove_if_exists(path, "Vim tutor.lnk");
299-
remove_if_exists(path, "Vim online.url");
300-
if (stat(path, &st) == 0)
301-
{
302-
printf("removing %s\n", path);
303-
rmdir(path);
304-
}
303+
printf("removing %s\n", path);
304+
rmdir(path);
305305
}
306306
}
307307

src/userfunc.c

Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -770,25 +770,25 @@ is_function_cmd(char_u **cmd)
770770
static void
771771
function_using_block_scopes(ufunc_T *fp, cstack_T *cstack)
772772
{
773-
if (cstack != NULL && cstack->cs_idx >= 0)
774-
{
775-
int count = cstack->cs_idx + 1;
776-
int i;
773+
if (cstack == NULL || cstack->cs_idx < 0)
774+
return;
777775

778-
fp->uf_block_ids = ALLOC_MULT(int, count);
779-
if (fp->uf_block_ids != NULL)
780-
{
781-
mch_memmove(fp->uf_block_ids, cstack->cs_block_id,
782-
sizeof(int) * count);
783-
fp->uf_block_depth = count;
784-
}
776+
int count = cstack->cs_idx + 1;
777+
int i;
785778

786-
// Set flag in each block to indicate a function was defined. This
787-
// is used to keep the variable when leaving the block, see
788-
// hide_script_var().
789-
for (i = 0; i <= cstack->cs_idx; ++i)
790-
cstack->cs_flags[i] |= CSF_FUNC_DEF;
779+
fp->uf_block_ids = ALLOC_MULT(int, count);
780+
if (fp->uf_block_ids != NULL)
781+
{
782+
mch_memmove(fp->uf_block_ids, cstack->cs_block_id,
783+
sizeof(int) * count);
784+
fp->uf_block_depth = count;
791785
}
786+
787+
// Set flag in each block to indicate a function was defined. This
788+
// is used to keep the variable when leaving the block, see
789+
// hide_script_var().
790+
for (i = 0; i <= cstack->cs_idx; ++i)
791+
cstack->cs_flags[i] |= CSF_FUNC_DEF;
792792
}
793793

794794
/*
@@ -2433,21 +2433,20 @@ func_remove(ufunc_T *fp)
24332433
return FALSE;
24342434

24352435
hi = hash_find(&func_hashtab, UF2HIKEY(fp));
2436-
if (!HASHITEM_EMPTY(hi))
2436+
if (HASHITEM_EMPTY(hi))
2437+
return FALSE;
2438+
2439+
// When there is a def-function index do not actually remove the
2440+
// function, so we can find the index when defining the function again.
2441+
// Do remove it when it's a copy.
2442+
if (fp->uf_def_status == UF_COMPILED && (fp->uf_flags & FC_COPY) == 0)
24372443
{
2438-
// When there is a def-function index do not actually remove the
2439-
// function, so we can find the index when defining the function again.
2440-
// Do remove it when it's a copy.
2441-
if (fp->uf_def_status == UF_COMPILED && (fp->uf_flags & FC_COPY) == 0)
2442-
{
2443-
fp->uf_flags |= FC_DEAD;
2444-
return FALSE;
2445-
}
2446-
hash_remove(&func_hashtab, hi, "remove function");
2447-
fp->uf_flags |= FC_DELETED;
2448-
return TRUE;
2444+
fp->uf_flags |= FC_DEAD;
2445+
return FALSE;
24492446
}
2450-
return FALSE;
2447+
hash_remove(&func_hashtab, hi, "remove function");
2448+
fp->uf_flags |= FC_DELETED;
2449+
return TRUE;
24512450
}
24522451

24532452
static void

src/version.c

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -57,26 +57,26 @@ char *longVersion = NULL;
5757
void
5858
init_longVersion(void)
5959
{
60-
if (longVersion == NULL)
61-
{
60+
if (longVersion != NULL)
61+
return;
62+
6263
#ifdef BUILD_DATE
63-
char *date_time = BUILD_DATE;
64+
char *date_time = BUILD_DATE;
6465
#else
65-
char *date_time = __DATE__ " " __TIME__;
66+
char *date_time = __DATE__ " " __TIME__;
6667
#endif
67-
char *msg = _("%s (%s, compiled %s)");
68-
size_t len = strlen(msg)
69-
+ strlen(VIM_VERSION_LONG_ONLY)
70-
+ strlen(VIM_VERSION_DATE_ONLY)
71-
+ strlen(date_time);
68+
char *msg = _("%s (%s, compiled %s)");
69+
size_t len = strlen(msg)
70+
+ strlen(VIM_VERSION_LONG_ONLY)
71+
+ strlen(VIM_VERSION_DATE_ONLY)
72+
+ strlen(date_time);
7273

73-
longVersion = alloc(len);
74-
if (longVersion == NULL)
75-
longVersion = VIM_VERSION_LONG;
76-
else
77-
vim_snprintf(longVersion, len, msg,
78-
VIM_VERSION_LONG_ONLY, VIM_VERSION_DATE_ONLY, date_time);
79-
}
74+
longVersion = alloc(len);
75+
if (longVersion == NULL)
76+
longVersion = VIM_VERSION_LONG;
77+
else
78+
vim_snprintf(longVersion, len, msg,
79+
VIM_VERSION_LONG_ONLY, VIM_VERSION_DATE_ONLY, date_time);
8080
}
8181
# endif
8282
#else
@@ -695,6 +695,8 @@ static char *(features[]) =
695695

696696
static int included_patches[] =
697697
{ /* Add new patch number below this line */
698+
/**/
699+
1246,
698700
/**/
699701
1245,
700702
/**/

0 commit comments

Comments
 (0)