Skip to content

Commit a41e221

Browse files
yegappanbrammool
authored andcommitted
patch 9.0.1208: 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 #11819)
1 parent 450c7a9 commit a41e221

12 files changed

Lines changed: 1282 additions & 1276 deletions

File tree

src/netbeans.c

Lines changed: 87 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -938,13 +938,13 @@ nb_partialremove(linenr_T lnum, colnr_T first, colnr_T last)
938938
if (lastbyte >= oldlen)
939939
lastbyte = oldlen - 1;
940940
newtext = alloc(oldlen - (int)(lastbyte - first));
941-
if (newtext != NULL)
942-
{
943-
mch_memmove(newtext, oldtext, first);
944-
STRMOVE(newtext + first, oldtext + lastbyte + 1);
945-
nbdebug((" NEW LINE %ld: %s\n", lnum, newtext));
946-
ml_replace(lnum, newtext, FALSE);
947-
}
941+
if (newtext == NULL)
942+
return;
943+
944+
mch_memmove(newtext, oldtext, first);
945+
STRMOVE(newtext + first, oldtext + lastbyte + 1);
946+
nbdebug((" NEW LINE %ld: %s\n", lnum, newtext));
947+
ml_replace(lnum, newtext, FALSE);
948948
}
949949

950950
/*
@@ -960,12 +960,12 @@ nb_joinlines(linenr_T first, linenr_T other)
960960
len_first = (int)STRLEN(ml_get(first));
961961
len_other = (int)STRLEN(ml_get(other));
962962
p = alloc(len_first + len_other + 1);
963-
if (p != NULL)
964-
{
965-
mch_memmove(p, ml_get(first), len_first);
966-
mch_memmove(p + len_first, ml_get(other), len_other + 1);
967-
ml_replace(first, p, FALSE);
968-
}
963+
if (p == NULL)
964+
return;
965+
966+
mch_memmove(p, ml_get(first), len_first);
967+
mch_memmove(p + len_first, ml_get(other), len_other + 1);
968+
ml_replace(first, p, FALSE);
969969
}
970970

971971
#define SKIP_STOP 2
@@ -2247,13 +2247,14 @@ nb_do_cmd(
22472247
static void
22482248
nb_set_curbuf(buf_T *buf)
22492249
{
2250-
if (curbuf != buf) {
2251-
if (buf_jump_open_win(buf) != NULL)
2252-
return;
2253-
if ((swb_flags & SWB_USETAB) && buf_jump_open_tab(buf) != NULL)
2254-
return;
2255-
set_curbuf(buf, DOBUF_GOTO);
2256-
}
2250+
if (curbuf == buf)
2251+
return;
2252+
2253+
if (buf_jump_open_win(buf) != NULL)
2254+
return;
2255+
if ((swb_flags & SWB_USETAB) && buf_jump_open_tab(buf) != NULL)
2256+
return;
2257+
set_curbuf(buf, DOBUF_GOTO);
22572258
}
22582259

22592260
/*
@@ -2364,14 +2365,14 @@ nb_init_graphics(void)
23642365
{
23652366
static int did_init = FALSE;
23662367

2367-
if (!did_init)
2368-
{
2369-
coloncmd(":highlight NBGuarded guibg=Cyan guifg=Black"
2370-
" ctermbg=LightCyan ctermfg=Black");
2371-
coloncmd(":sign define %d linehl=NBGuarded", GUARDED);
2368+
if (did_init)
2369+
return;
23722370

2373-
did_init = TRUE;
2374-
}
2371+
coloncmd(":highlight NBGuarded guibg=Cyan guifg=Black"
2372+
" ctermbg=LightCyan ctermfg=Black");
2373+
coloncmd(":sign define %d linehl=NBGuarded", GUARDED);
2374+
2375+
did_init = TRUE;
23752376
}
23762377

23772378
/*
@@ -2468,29 +2469,29 @@ netbeans_beval_cb(
24682469
if (!can_use_beval() || !NETBEANS_OPEN)
24692470
return;
24702471

2471-
if (get_beval_info(beval, TRUE, &wp, &lnum, &text, &col) == OK)
2472+
if (get_beval_info(beval, TRUE, &wp, &lnum, &text, &col) != OK)
2473+
return;
2474+
2475+
// Send debugger request. Only when the text is of reasonable
2476+
// length.
2477+
if (text != NULL && text[0] != NUL && STRLEN(text) < MAXPATHL)
24722478
{
2473-
// Send debugger request. Only when the text is of reasonable
2474-
// length.
2475-
if (text != NULL && text[0] != NUL && STRLEN(text) < MAXPATHL)
2479+
buf = alloc(MAXPATHL * 2 + 25);
2480+
if (buf != NULL)
24762481
{
2477-
buf = alloc(MAXPATHL * 2 + 25);
2478-
if (buf != NULL)
2482+
p = nb_quote(text);
2483+
if (p != NULL)
24792484
{
2480-
p = nb_quote(text);
2481-
if (p != NULL)
2482-
{
2483-
vim_snprintf(buf, MAXPATHL * 2 + 25,
2484-
"0:balloonText=%d \"%s\"\n", r_cmdno, p);
2485-
vim_free(p);
2486-
}
2487-
nbdebug(("EVT: %s", buf));
2488-
nb_send(buf, "netbeans_beval_cb");
2489-
vim_free(buf);
2485+
vim_snprintf(buf, MAXPATHL * 2 + 25,
2486+
"0:balloonText=%d \"%s\"\n", r_cmdno, p);
2487+
vim_free(p);
24902488
}
2489+
nbdebug(("EVT: %s", buf));
2490+
nb_send(buf, "netbeans_beval_cb");
2491+
vim_free(buf);
24912492
}
2492-
vim_free(text);
24932493
}
2494+
vim_free(text);
24942495
}
24952496
#endif
24962497

@@ -2555,12 +2556,12 @@ set_ref_in_nb_channel(int copyID)
25552556
int abort = FALSE;
25562557
typval_T tv;
25572558

2558-
if (nb_channel != NULL)
2559-
{
2560-
tv.v_type = VAR_CHANNEL;
2561-
tv.vval.v_channel = nb_channel;
2562-
abort = set_ref_in_item(&tv, copyID, NULL, NULL);
2563-
}
2559+
if (nb_channel == NULL)
2560+
return FALSE;
2561+
2562+
tv.v_type = VAR_CHANNEL;
2563+
tv.vval.v_channel = nb_channel;
2564+
abort = set_ref_in_item(&tv, copyID, NULL, NULL);
25642565
return abort;
25652566
}
25662567
#endif
@@ -2827,22 +2828,22 @@ netbeans_button_release(int button)
28272828

28282829
bufno = nb_getbufno(curbuf);
28292830

2830-
if (bufno >= 0 && curwin != NULL && curwin->w_buffer == curbuf)
2831-
{
2832-
int col = mouse_col - curwin->w_wincol
2833-
- ((curwin->w_p_nu || curwin->w_p_rnu) ? 9 : 1);
2834-
long off = pos2off(curbuf, &curwin->w_cursor);
2831+
if (bufno < 0 || curwin == NULL || curwin->w_buffer != curbuf)
2832+
return;
28352833

2836-
// sync the cursor position
2837-
sprintf(buf, "%d:newDotAndMark=%d %ld %ld\n", bufno, r_cmdno, off, off);
2838-
nbdebug(("EVT: %s", buf));
2839-
nb_send(buf, "netbeans_button_release[newDotAndMark]");
2834+
int col = mouse_col - curwin->w_wincol
2835+
- ((curwin->w_p_nu || curwin->w_p_rnu) ? 9 : 1);
2836+
long off = pos2off(curbuf, &curwin->w_cursor);
28402837

2841-
sprintf(buf, "%d:buttonRelease=%d %d %ld %d\n", bufno, r_cmdno,
2842-
button, (long)curwin->w_cursor.lnum, col);
2843-
nbdebug(("EVT: %s", buf));
2844-
nb_send(buf, "netbeans_button_release");
2845-
}
2838+
// sync the cursor position
2839+
sprintf(buf, "%d:newDotAndMark=%d %ld %ld\n", bufno, r_cmdno, off, off);
2840+
nbdebug(("EVT: %s", buf));
2841+
nb_send(buf, "netbeans_button_release[newDotAndMark]");
2842+
2843+
sprintf(buf, "%d:buttonRelease=%d %d %ld %d\n", bufno, r_cmdno,
2844+
button, (long)curwin->w_cursor.lnum, col);
2845+
nbdebug(("EVT: %s", buf));
2846+
nb_send(buf, "netbeans_button_release");
28462847
}
28472848

28482849

@@ -3308,29 +3309,27 @@ get_buf_size(buf_T *bufp)
33083309

33093310
if (bufp->b_ml.ml_flags & ML_EMPTY)
33103311
return 0;
3312+
3313+
if (get_fileformat(bufp) == EOL_DOS)
3314+
eol_size = 2;
33113315
else
3316+
eol_size = 1;
3317+
for (lnum = 1; lnum <= bufp->b_ml.ml_line_count; ++lnum)
33123318
{
3313-
if (get_fileformat(bufp) == EOL_DOS)
3314-
eol_size = 2;
3315-
else
3316-
eol_size = 1;
3317-
for (lnum = 1; lnum <= bufp->b_ml.ml_line_count; ++lnum)
3319+
char_count += (long)STRLEN(ml_get_buf(bufp, lnum, FALSE))
3320+
+ eol_size;
3321+
// Check for a CTRL-C every 100000 characters
3322+
if (char_count > last_check)
33183323
{
3319-
char_count += (long)STRLEN(ml_get_buf(bufp, lnum, FALSE))
3320-
+ eol_size;
3321-
// Check for a CTRL-C every 100000 characters
3322-
if (char_count > last_check)
3323-
{
3324-
ui_breakcheck();
3325-
if (got_int)
3326-
return char_count;
3327-
last_check = char_count + 100000L;
3328-
}
3324+
ui_breakcheck();
3325+
if (got_int)
3326+
return char_count;
3327+
last_check = char_count + 100000L;
33293328
}
3330-
// Correction for when last line doesn't have an EOL.
3331-
if (!bufp->b_p_eol && (bufp->b_p_bin || !bufp->b_p_fixeol))
3332-
char_count -= eol_size;
33333329
}
3330+
// Correction for when last line doesn't have an EOL.
3331+
if (!bufp->b_p_eol && (bufp->b_p_bin || !bufp->b_p_fixeol))
3332+
char_count -= eol_size;
33343333

33353334
return char_count;
33363335
}
@@ -3393,12 +3392,12 @@ pos2off(buf_T *buf, pos_T *pos)
33933392
{
33943393
long offset = 0;
33953394

3396-
if (!(buf->b_ml.ml_flags & ML_EMPTY))
3397-
{
3398-
if ((offset = ml_find_line_or_offset(buf, pos->lnum, 0)) < 0)
3399-
return 0;
3400-
offset += pos->col;
3401-
}
3395+
if (buf->b_ml.ml_flags & ML_EMPTY)
3396+
return 0;
3397+
3398+
if ((offset = ml_find_line_or_offset(buf, pos->lnum, 0)) < 0)
3399+
return 0;
3400+
offset += pos->col;
34023401

34033402
return offset;
34043403
}

0 commit comments

Comments
 (0)