From dc4daa3a3915fba11ac87d27977240d9a5e0d47d Mon Sep 17 00:00:00 2001 From: Yegappan Lakshmanan Date: Mon, 2 Jan 2023 16:54:53 +0000 Subject: patch 9.0.1132: code is indented more than needed Problem: Code is indented more than needed. Solution: Use an early return to reduce indentation. (Yegappan Lakshmanan, closes #11769) --- src/fold.c | 170 ++++++++++++++++++++++++++++++------------------------------- 1 file changed, 85 insertions(+), 85 deletions(-) (limited to 'src/fold.c') diff --git a/src/fold.c b/src/fold.c index a226d6fd2f..d722a56d0c 100644 --- a/src/fold.c +++ b/src/fold.c @@ -644,59 +644,59 @@ foldCreate(linenr_T start, linenr_T end) i = (int)(fp - (fold_T *)gap->ga_data); } - if (ga_grow(gap, 1) == OK) - { - fp = (fold_T *)gap->ga_data + i; - ga_init2(&fold_ga, sizeof(fold_T), 10); + if (ga_grow(gap, 1) != OK) + return; - // Count number of folds that will be contained in the new fold. - for (cont = 0; i + cont < gap->ga_len; ++cont) - if (fp[cont].fd_top > end_rel) - break; - if (cont > 0 && ga_grow(&fold_ga, cont) == OK) - { - // If the first fold starts before the new fold, let the new fold - // start there. Otherwise the existing fold would change. - if (start_rel > fp->fd_top) - start_rel = fp->fd_top; - - // When last contained fold isn't completely contained, adjust end - // of new fold. - if (end_rel < fp[cont - 1].fd_top + fp[cont - 1].fd_len - 1) - end_rel = fp[cont - 1].fd_top + fp[cont - 1].fd_len - 1; - // Move contained folds to inside new fold. - mch_memmove(fold_ga.ga_data, fp, sizeof(fold_T) * cont); - fold_ga.ga_len += cont; - i += cont; - - // Adjust line numbers in contained folds to be relative to the - // new fold. - for (j = 0; j < cont; ++j) - ((fold_T *)fold_ga.ga_data)[j].fd_top -= start_rel; - } - // Move remaining entries to after the new fold. - if (i < gap->ga_len) - mch_memmove(fp + 1, (fold_T *)gap->ga_data + i, - sizeof(fold_T) * (gap->ga_len - i)); - gap->ga_len = gap->ga_len + 1 - cont; - - // insert new fold - fp->fd_nested = fold_ga; - fp->fd_top = start_rel; - fp->fd_len = end_rel - start_rel + 1; - - // We want the new fold to be closed. If it would remain open because - // of using 'foldlevel', need to adjust fd_flags of containing folds. - if (use_level && !closed && level < curwin->w_p_fdl) - closeFold(start, 1L); - if (!use_level) - curwin->w_fold_manual = TRUE; - fp->fd_flags = FD_CLOSED; - fp->fd_small = MAYBE; + fp = (fold_T *)gap->ga_data + i; + ga_init2(&fold_ga, sizeof(fold_T), 10); - // redraw - changed_window_setting(); - } + // Count number of folds that will be contained in the new fold. + for (cont = 0; i + cont < gap->ga_len; ++cont) + if (fp[cont].fd_top > end_rel) + break; + if (cont > 0 && ga_grow(&fold_ga, cont) == OK) + { + // If the first fold starts before the new fold, let the new fold + // start there. Otherwise the existing fold would change. + if (start_rel > fp->fd_top) + start_rel = fp->fd_top; + + // When last contained fold isn't completely contained, adjust end + // of new fold. + if (end_rel < fp[cont - 1].fd_top + fp[cont - 1].fd_len - 1) + end_rel = fp[cont - 1].fd_top + fp[cont - 1].fd_len - 1; + // Move contained folds to inside new fold. + mch_memmove(fold_ga.ga_data, fp, sizeof(fold_T) * cont); + fold_ga.ga_len += cont; + i += cont; + + // Adjust line numbers in contained folds to be relative to the + // new fold. + for (j = 0; j < cont; ++j) + ((fold_T *)fold_ga.ga_data)[j].fd_top -= start_rel; + } + // Move remaining entries to after the new fold. + if (i < gap->ga_len) + mch_memmove(fp + 1, (fold_T *)gap->ga_data + i, + sizeof(fold_T) * (gap->ga_len - i)); + gap->ga_len = gap->ga_len + 1 - cont; + + // insert new fold + fp->fd_nested = fold_ga; + fp->fd_top = start_rel; + fp->fd_len = end_rel - start_rel + 1; + + // We want the new fold to be closed. If it would remain open because + // of using 'foldlevel', need to adjust fd_flags of containing folds. + if (use_level && !closed && level < curwin->w_p_fdl) + closeFold(start, 1L); + if (!use_level) + curwin->w_fold_manual = TRUE; + fp->fd_flags = FD_CLOSED; + fp->fd_small = MAYBE; + + // redraw + changed_window_setting(); } // deleteFold() {{{2 @@ -1719,27 +1719,27 @@ checkSmall( int count; int n; - if (fp->fd_small == MAYBE) - { - // Mark any nested folds to maybe-small - setSmallMaybe(&fp->fd_nested); + if (fp->fd_small != MAYBE) + return; - if (fp->fd_len > curwin->w_p_fml) - fp->fd_small = FALSE; - else + // Mark any nested folds to maybe-small + setSmallMaybe(&fp->fd_nested); + + if (fp->fd_len > curwin->w_p_fml) + fp->fd_small = FALSE; + else + { + count = 0; + for (n = 0; n < fp->fd_len; ++n) { - count = 0; - for (n = 0; n < fp->fd_len; ++n) + count += plines_win_nofold(wp, fp->fd_top + lnum_off + n); + if (count > curwin->w_p_fml) { - count += plines_win_nofold(wp, fp->fd_top + lnum_off + n); - if (count > curwin->w_p_fml) - { - fp->fd_small = FALSE; - return; - } + fp->fd_small = FALSE; + return; } - fp->fd_small = TRUE; } + fp->fd_small = TRUE; } } @@ -1799,26 +1799,26 @@ foldAddMarker(linenr_T lnum, char_u *marker, int markerlen) line = ml_get(lnum); line_len = (int)STRLEN(line); - if (u_save(lnum - 1, lnum + 1) == OK) - { - // Check if the line ends with an unclosed comment - (void)skip_comment(line, FALSE, FALSE, &line_is_comment); - newline = alloc(line_len + markerlen + STRLEN(cms) + 1); - if (newline == NULL) - return; - STRCPY(newline, line); - // Append the marker to the end of the line - if (p == NULL || line_is_comment) - vim_strncpy(newline + line_len, marker, markerlen); - else - { - STRCPY(newline + line_len, cms); - STRNCPY(newline + line_len + (p - cms), marker, markerlen); - STRCPY(newline + line_len + (p - cms) + markerlen, p + 2); - } + if (u_save(lnum - 1, lnum + 1) != OK) + return; - ml_replace(lnum, newline, FALSE); + // Check if the line ends with an unclosed comment + (void)skip_comment(line, FALSE, FALSE, &line_is_comment); + newline = alloc(line_len + markerlen + STRLEN(cms) + 1); + if (newline == NULL) + return; + STRCPY(newline, line); + // Append the marker to the end of the line + if (p == NULL || line_is_comment) + vim_strncpy(newline + line_len, marker, markerlen); + else + { + STRCPY(newline + line_len, cms); + STRNCPY(newline + line_len + (p - cms), marker, markerlen); + STRCPY(newline + line_len + (p - cms) + markerlen, p + 2); } + + ml_replace(lnum, newline, FALSE); } // deleteFoldMarkers() {{{2 -- cgit v1.2.3