Skip to content

Commit 465de3a

Browse files
yegappanbrammool
authored andcommitted
patch 9.0.1098: code uses too much indent
Problem: Code uses too much indent. Solution: Use an early return. (Yegappan Lakshmanan, closes #11747)
1 parent b3d6143 commit 465de3a

6 files changed

Lines changed: 219 additions & 215 deletions

File tree

src/cmdhist.c

Lines changed: 34 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -460,44 +460,46 @@ del_history_entry(int histype, char_u *str)
460460
int last;
461461
int found = FALSE;
462462

463-
regmatch.regprog = NULL;
463+
if (hislen == 0 || histype < 0 || histype >= HIST_COUNT || *str == NUL
464+
|| hisidx[histype] < 0)
465+
return FALSE;
466+
467+
idx = hisidx[histype];
468+
regmatch.regprog = vim_regcomp(str, RE_MAGIC + RE_STRING);
469+
if (regmatch.regprog == NULL)
470+
return FALSE;
471+
464472
regmatch.rm_ic = FALSE; // always match case
465-
if (hislen != 0
466-
&& histype >= 0
467-
&& histype < HIST_COUNT
468-
&& *str != NUL
469-
&& (idx = hisidx[histype]) >= 0
470-
&& (regmatch.regprog = vim_regcomp(str, RE_MAGIC + RE_STRING))
471-
!= NULL)
473+
474+
i = last = idx;
475+
do
472476
{
473-
i = last = idx;
474-
do
477+
hisptr = &history[histype][i];
478+
if (hisptr->hisstr == NULL)
479+
break;
480+
if (vim_regexec(&regmatch, hisptr->hisstr, (colnr_T)0))
475481
{
476-
hisptr = &history[histype][i];
477-
if (hisptr->hisstr == NULL)
478-
break;
479-
if (vim_regexec(&regmatch, hisptr->hisstr, (colnr_T)0))
482+
found = TRUE;
483+
vim_free(hisptr->hisstr);
484+
clear_hist_entry(hisptr);
485+
}
486+
else
487+
{
488+
if (i != last)
480489
{
481-
found = TRUE;
482-
vim_free(hisptr->hisstr);
490+
history[histype][last] = *hisptr;
483491
clear_hist_entry(hisptr);
484492
}
485-
else
486-
{
487-
if (i != last)
488-
{
489-
history[histype][last] = *hisptr;
490-
clear_hist_entry(hisptr);
491-
}
492-
if (--last < 0)
493-
last += hislen;
494-
}
495-
if (--i < 0)
496-
i += hislen;
497-
} while (i != idx);
498-
if (history[histype][idx].hisstr == NULL)
499-
hisidx[histype] = -1;
500-
}
493+
if (--last < 0)
494+
last += hislen;
495+
}
496+
if (--i < 0)
497+
i += hislen;
498+
} while (i != idx);
499+
500+
if (history[histype][idx].hisstr == NULL)
501+
hisidx[histype] = -1;
502+
501503
vim_regfree(regmatch.regprog);
502504
return found;
503505
}

src/debugger.c

Lines changed: 69 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -682,44 +682,44 @@ ex_breakadd(exarg_T *eap)
682682
gap = &prof_ga;
683683
#endif
684684

685-
if (dbg_parsearg(eap->arg, gap) == OK)
686-
{
687-
bp = &DEBUGGY(gap, gap->ga_len);
688-
bp->dbg_forceit = eap->forceit;
685+
if (dbg_parsearg(eap->arg, gap) != OK)
686+
return;
689687

690-
if (bp->dbg_type != DBG_EXPR)
688+
bp = &DEBUGGY(gap, gap->ga_len);
689+
bp->dbg_forceit = eap->forceit;
690+
691+
if (bp->dbg_type != DBG_EXPR)
692+
{
693+
pat = file_pat_to_reg_pat(bp->dbg_name, NULL, NULL, FALSE);
694+
if (pat != NULL)
691695
{
692-
pat = file_pat_to_reg_pat(bp->dbg_name, NULL, NULL, FALSE);
693-
if (pat != NULL)
694-
{
695-
bp->dbg_prog = vim_regcomp(pat, RE_MAGIC + RE_STRING);
696-
vim_free(pat);
697-
}
698-
if (pat == NULL || bp->dbg_prog == NULL)
699-
vim_free(bp->dbg_name);
700-
else
701-
{
702-
if (bp->dbg_lnum == 0) // default line number is 1
703-
bp->dbg_lnum = 1;
704-
#ifdef FEAT_PROFILE
705-
if (eap->cmdidx != CMD_profile)
706-
#endif
707-
{
708-
DEBUGGY(gap, gap->ga_len).dbg_nr = ++last_breakp;
709-
++debug_tick;
710-
}
711-
++gap->ga_len;
712-
}
696+
bp->dbg_prog = vim_regcomp(pat, RE_MAGIC + RE_STRING);
697+
vim_free(pat);
713698
}
699+
if (pat == NULL || bp->dbg_prog == NULL)
700+
vim_free(bp->dbg_name);
714701
else
715702
{
716-
// DBG_EXPR
717-
DEBUGGY(gap, gap->ga_len++).dbg_nr = ++last_breakp;
718-
++debug_tick;
719-
if (gap == &dbg_breakp)
720-
has_expr_breakpoint = TRUE;
703+
if (bp->dbg_lnum == 0) // default line number is 1
704+
bp->dbg_lnum = 1;
705+
#ifdef FEAT_PROFILE
706+
if (eap->cmdidx != CMD_profile)
707+
#endif
708+
{
709+
DEBUGGY(gap, gap->ga_len).dbg_nr = ++last_breakp;
710+
++debug_tick;
711+
}
712+
++gap->ga_len;
721713
}
722714
}
715+
else
716+
{
717+
// DBG_EXPR
718+
DEBUGGY(gap, gap->ga_len++).dbg_nr = ++last_breakp;
719+
++debug_tick;
720+
if (gap == &dbg_breakp)
721+
has_expr_breakpoint = TRUE;
722+
}
723723
}
724724

725725
/*
@@ -822,36 +822,37 @@ ex_breakdel(exarg_T *eap)
822822
}
823823

824824
if (todel < 0)
825+
{
825826
semsg(_(e_breakpoint_not_found_str), eap->arg);
826-
else
827+
return;
828+
}
829+
830+
while (gap->ga_len > 0)
827831
{
828-
while (gap->ga_len > 0)
829-
{
830-
vim_free(DEBUGGY(gap, todel).dbg_name);
832+
vim_free(DEBUGGY(gap, todel).dbg_name);
831833
#ifdef FEAT_EVAL
832-
if (DEBUGGY(gap, todel).dbg_type == DBG_EXPR
833-
&& DEBUGGY(gap, todel).dbg_val != NULL)
834-
free_tv(DEBUGGY(gap, todel).dbg_val);
834+
if (DEBUGGY(gap, todel).dbg_type == DBG_EXPR
835+
&& DEBUGGY(gap, todel).dbg_val != NULL)
836+
free_tv(DEBUGGY(gap, todel).dbg_val);
835837
#endif
836-
vim_regfree(DEBUGGY(gap, todel).dbg_prog);
837-
--gap->ga_len;
838-
if (todel < gap->ga_len)
839-
mch_memmove(&DEBUGGY(gap, todel), &DEBUGGY(gap, todel + 1),
840-
(gap->ga_len - todel) * sizeof(struct debuggy));
838+
vim_regfree(DEBUGGY(gap, todel).dbg_prog);
839+
--gap->ga_len;
840+
if (todel < gap->ga_len)
841+
mch_memmove(&DEBUGGY(gap, todel), &DEBUGGY(gap, todel + 1),
842+
(gap->ga_len - todel) * sizeof(struct debuggy));
841843
#ifdef FEAT_PROFILE
842-
if (eap->cmdidx == CMD_breakdel)
844+
if (eap->cmdidx == CMD_breakdel)
843845
#endif
844-
++debug_tick;
845-
if (!del_all)
846-
break;
847-
}
848-
849-
// If all breakpoints were removed clear the array.
850-
if (gap->ga_len == 0)
851-
ga_clear(gap);
852-
if (gap == &dbg_breakp)
853-
update_has_expr_breakpoint();
846+
++debug_tick;
847+
if (!del_all)
848+
break;
854849
}
850+
851+
// If all breakpoints were removed clear the array.
852+
if (gap->ga_len == 0)
853+
ga_clear(gap);
854+
if (gap == &dbg_breakp)
855+
update_has_expr_breakpoint();
855856
}
856857

857858
/*
@@ -864,23 +865,26 @@ ex_breaklist(exarg_T *eap UNUSED)
864865
int i;
865866

866867
if (dbg_breakp.ga_len == 0)
868+
{
867869
msg(_("No breakpoints defined"));
868-
else
869-
for (i = 0; i < dbg_breakp.ga_len; ++i)
870-
{
871-
bp = &BREAKP(i);
872-
if (bp->dbg_type == DBG_FILE)
873-
home_replace(NULL, bp->dbg_name, NameBuff, MAXPATHL, TRUE);
874-
if (bp->dbg_type != DBG_EXPR)
875-
smsg(_("%3d %s %s line %ld"),
870+
return;
871+
}
872+
873+
for (i = 0; i < dbg_breakp.ga_len; ++i)
874+
{
875+
bp = &BREAKP(i);
876+
if (bp->dbg_type == DBG_FILE)
877+
home_replace(NULL, bp->dbg_name, NameBuff, MAXPATHL, TRUE);
878+
if (bp->dbg_type != DBG_EXPR)
879+
smsg(_("%3d %s %s line %ld"),
876880
bp->dbg_nr,
877881
bp->dbg_type == DBG_FUNC ? "func" : "file",
878882
bp->dbg_type == DBG_FUNC ? bp->dbg_name : NameBuff,
879883
(long)bp->dbg_lnum);
880-
else
881-
smsg(_("%3d expr %s"),
884+
else
885+
smsg(_("%3d expr %s"),
882886
bp->dbg_nr, bp->dbg_name);
883-
}
887+
}
884888
}
885889

886890
/*

src/diff.c

Lines changed: 50 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1180,44 +1180,40 @@ diff_file(diffio_T *dio)
11801180
#endif
11811181
// Use xdiff for generating the diff.
11821182
if (dio->dio_internal)
1183-
{
11841183
return diff_file_internal(dio);
1185-
}
1186-
else
1187-
{
1188-
len = STRLEN(tmp_orig) + STRLEN(tmp_new)
1189-
+ STRLEN(tmp_diff) + STRLEN(p_srr) + 27;
1190-
cmd = alloc(len);
1191-
if (cmd == NULL)
1192-
return FAIL;
11931184

1194-
// We don't want $DIFF_OPTIONS to get in the way.
1195-
if (getenv("DIFF_OPTIONS"))
1196-
vim_setenv((char_u *)"DIFF_OPTIONS", (char_u *)"");
1185+
len = STRLEN(tmp_orig) + STRLEN(tmp_new)
1186+
+ STRLEN(tmp_diff) + STRLEN(p_srr) + 27;
1187+
cmd = alloc(len);
1188+
if (cmd == NULL)
1189+
return FAIL;
1190+
1191+
// We don't want $DIFF_OPTIONS to get in the way.
1192+
if (getenv("DIFF_OPTIONS"))
1193+
vim_setenv((char_u *)"DIFF_OPTIONS", (char_u *)"");
11971194

1198-
// Build the diff command and execute it. Always use -a, binary
1199-
// differences are of no use. Ignore errors, diff returns
1200-
// non-zero when differences have been found.
1201-
vim_snprintf((char *)cmd, len, "diff %s%s%s%s%s%s%s%s %s",
1202-
diff_a_works == FALSE ? "" : "-a ",
1195+
// Build the diff command and execute it. Always use -a, binary
1196+
// differences are of no use. Ignore errors, diff returns
1197+
// non-zero when differences have been found.
1198+
vim_snprintf((char *)cmd, len, "diff %s%s%s%s%s%s%s%s %s",
1199+
diff_a_works == FALSE ? "" : "-a ",
12031200
#if defined(MSWIN)
1204-
diff_bin_works == TRUE ? "--binary " : "",
1201+
diff_bin_works == TRUE ? "--binary " : "",
12051202
#else
1206-
"",
1203+
"",
12071204
#endif
1208-
(diff_flags & DIFF_IWHITE) ? "-b " : "",
1209-
(diff_flags & DIFF_IWHITEALL) ? "-w " : "",
1210-
(diff_flags & DIFF_IWHITEEOL) ? "-Z " : "",
1211-
(diff_flags & DIFF_IBLANK) ? "-B " : "",
1212-
(diff_flags & DIFF_ICASE) ? "-i " : "",
1213-
tmp_orig, tmp_new);
1214-
append_redir(cmd, (int)len, p_srr, tmp_diff);
1215-
block_autocmds(); // avoid ShellCmdPost stuff
1216-
(void)call_shell(cmd, SHELL_FILTER|SHELL_SILENT|SHELL_DOOUT);
1217-
unblock_autocmds();
1218-
vim_free(cmd);
1219-
return OK;
1220-
}
1205+
(diff_flags & DIFF_IWHITE) ? "-b " : "",
1206+
(diff_flags & DIFF_IWHITEALL) ? "-w " : "",
1207+
(diff_flags & DIFF_IWHITEEOL) ? "-Z " : "",
1208+
(diff_flags & DIFF_IBLANK) ? "-B " : "",
1209+
(diff_flags & DIFF_ICASE) ? "-i " : "",
1210+
tmp_orig, tmp_new);
1211+
append_redir(cmd, (int)len, p_srr, tmp_diff);
1212+
block_autocmds(); // avoid ShellCmdPost stuff
1213+
(void)call_shell(cmd, SHELL_FILTER|SHELL_SILENT|SHELL_DOOUT);
1214+
unblock_autocmds();
1215+
vim_free(cmd);
1216+
return OK;
12211217
}
12221218

12231219
/*
@@ -1432,31 +1428,31 @@ ex_diffsplit(exarg_T *eap)
14321428
// don't use a new tab page, each tab page has its own diffs
14331429
cmdmod.cmod_tab = 0;
14341430

1435-
if (win_split(0, (diff_flags & DIFF_VERTICAL) ? WSP_VERT : 0) != FAIL)
1436-
{
1437-
// Pretend it was a ":split fname" command
1438-
eap->cmdidx = CMD_split;
1439-
curwin->w_p_diff = TRUE;
1440-
do_exedit(eap, old_curwin);
1431+
if (win_split(0, (diff_flags & DIFF_VERTICAL) ? WSP_VERT : 0) == FAIL)
1432+
return;
14411433

1442-
if (curwin != old_curwin) // split must have worked
1443-
{
1444-
// Set 'diff', 'scrollbind' on and 'wrap' off.
1445-
diff_win_options(curwin, TRUE);
1446-
if (win_valid(old_curwin))
1447-
{
1448-
diff_win_options(old_curwin, TRUE);
1434+
// Pretend it was a ":split fname" command
1435+
eap->cmdidx = CMD_split;
1436+
curwin->w_p_diff = TRUE;
1437+
do_exedit(eap, old_curwin);
14491438

1450-
if (bufref_valid(&old_curbuf))
1451-
// Move the cursor position to that of the old window.
1452-
curwin->w_cursor.lnum = diff_get_corresponding_line(
1453-
old_curbuf.br_buf, old_curwin->w_cursor.lnum);
1454-
}
1455-
// Now that lines are folded scroll to show the cursor at the same
1456-
// relative position.
1457-
scroll_to_fraction(curwin, curwin->w_height);
1458-
}
1439+
if (curwin == old_curwin) // split didn't work
1440+
return;
1441+
1442+
// Set 'diff', 'scrollbind' on and 'wrap' off.
1443+
diff_win_options(curwin, TRUE);
1444+
if (win_valid(old_curwin))
1445+
{
1446+
diff_win_options(old_curwin, TRUE);
1447+
1448+
if (bufref_valid(&old_curbuf))
1449+
// Move the cursor position to that of the old window.
1450+
curwin->w_cursor.lnum = diff_get_corresponding_line(
1451+
old_curbuf.br_buf, old_curwin->w_cursor.lnum);
14591452
}
1453+
// Now that lines are folded scroll to show the cursor at the same
1454+
// relative position.
1455+
scroll_to_fraction(curwin, curwin->w_height);
14601456
}
14611457

14621458
/*

0 commit comments

Comments
 (0)