diff options
author | Felipe Oliveira Carvalho <felipekde@gmail.com> | 2014-12-13 10:55:51 -0300 |
---|---|---|
committer | Felipe Oliveira Carvalho <felipekde@gmail.com> | 2014-12-13 23:36:11 -0300 |
commit | 77135447e09903b45d1482da45869946212f7904 (patch) | |
tree | 53b17c11d4bfbe8031842cfb65ae5c53c5eb41d7 /src/nvim/getchar.c | |
parent | 64a32d55c59188f1e922ca438fdb2d65caa06665 (diff) | |
download | rneovim-77135447e09903b45d1482da45869946212f7904.tar.gz rneovim-77135447e09903b45d1482da45869946212f7904.tar.bz2 rneovim-77135447e09903b45d1482da45869946212f7904.zip |
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;
}
...
...
...
}
```
Diffstat (limited to 'src/nvim/getchar.c')
-rw-r--r-- | src/nvim/getchar.c | 53 |
1 files changed, 27 insertions, 26 deletions
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; |