From 77135447e09903b45d1482da45869946212f7904 Mon Sep 17 00:00:00 2001 From: Felipe Oliveira Carvalho Date: Sat, 13 Dec 2014 10:55:51 -0300 Subject: Reduce indentation level by early returning or continuing loop Replace code like this ```c func() { if (cond) { ... ... ... } return ret; } ``` ```c for (...) { if (cond) { ... ... ... } } ``` with ```c func() { if (!cond) { return ret; } ... ... ... } ``` ```c for (...) { if (!cond) { continue; } ... ... ... } ``` --- src/nvim/getchar.c | 53 +++++++++++++++++++++++++++-------------------------- 1 file changed, 27 insertions(+), 26 deletions(-) (limited to 'src/nvim/getchar.c') diff --git a/src/nvim/getchar.c b/src/nvim/getchar.c index 5dec7e38fd..1d648cb9e9 100644 --- a/src/nvim/getchar.c +++ b/src/nvim/getchar.c @@ -680,33 +680,34 @@ static int read_redo(int init, int old_redo) p = bp->b_str; return OK; } - if ((c = *p) != NUL) { - /* Reverse the conversion done by add_char_buff() */ - /* For a multi-byte character get all the bytes and return the - * converted character. */ - if (has_mbyte && (c != K_SPECIAL || p[1] == KS_SPECIAL)) - n = MB_BYTE2LEN_CHECK(c); - else - n = 1; - for (i = 0;; ++i) { - if (c == K_SPECIAL) { /* special key or escaped K_SPECIAL */ - c = TO_SPECIAL(p[1], p[2]); - p += 2; - } - if (*++p == NUL && bp->b_next != NULL) { - bp = bp->b_next; - p = bp->b_str; - } - buf[i] = c; - if (i == n - 1) { /* last byte of a character */ - if (n != 1) - c = (*mb_ptr2char)(buf); - break; - } - c = *p; - if (c == NUL) /* cannot happen? */ - break; + if ((c = *p) == NUL) { + return c; + } + /* Reverse the conversion done by add_char_buff() */ + /* For a multi-byte character get all the bytes and return the + * converted character. */ + if (has_mbyte && (c != K_SPECIAL || p[1] == KS_SPECIAL)) + n = MB_BYTE2LEN_CHECK(c); + else + n = 1; + for (i = 0;; ++i) { + if (c == K_SPECIAL) { /* special key or escaped K_SPECIAL */ + c = TO_SPECIAL(p[1], p[2]); + p += 2; } + if (*++p == NUL && bp->b_next != NULL) { + bp = bp->b_next; + p = bp->b_str; + } + buf[i] = c; + if (i == n - 1) { /* last byte of a character */ + if (n != 1) + c = (*mb_ptr2char)(buf); + break; + } + c = *p; + if (c == NUL) /* cannot happen? */ + break; } return c; -- cgit