Mercurial > vim
comparison src/register.c @ 31778:579c846086eb v9.0.1221
patch 9.0.1221: code is indented more than necessary
Commit: https://github.com/vim/vim/commit/f97a295ccaa9803367f3714cdefce4e2283c771d
Author: Yegappan Lakshmanan <yegappan@yahoo.com>
Date: Wed Jan 18 18:17:48 2023 +0000
patch 9.0.1221: 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 #11833)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Wed, 18 Jan 2023 19:30:03 +0100 |
parents | b53ab3c3e0c9 |
children | 4545f58c8490 |
comparison
equal
deleted
inserted
replaced
31777:84bb462086cf | 31778:579c846086eb |
---|---|
292 } | 292 } |
293 #endif | 293 #endif |
294 | 294 |
295 get_yank_register(name, 0); | 295 get_yank_register(name, 0); |
296 reg = ALLOC_ONE(yankreg_T); | 296 reg = ALLOC_ONE(yankreg_T); |
297 if (reg != NULL) | 297 if (reg == NULL) |
298 { | 298 return (void *)NULL; |
299 *reg = *y_current; | 299 |
300 if (copy) | 300 *reg = *y_current; |
301 { | 301 if (copy) |
302 // If we run out of memory some or all of the lines are empty. | 302 { |
303 if (reg->y_size == 0) | 303 // If we run out of memory some or all of the lines are empty. |
304 reg->y_array = NULL; | 304 if (reg->y_size == 0) |
305 else | 305 reg->y_array = NULL; |
306 reg->y_array = ALLOC_MULT(char_u *, reg->y_size); | |
307 if (reg->y_array != NULL) | |
308 { | |
309 for (i = 0; i < reg->y_size; ++i) | |
310 reg->y_array[i] = vim_strsave(y_current->y_array[i]); | |
311 } | |
312 } | |
313 else | 306 else |
314 y_current->y_array = NULL; | 307 reg->y_array = ALLOC_MULT(char_u *, reg->y_size); |
315 } | 308 if (reg->y_array != NULL) |
309 { | |
310 for (i = 0; i < reg->y_size; ++i) | |
311 reg->y_array[i] = vim_strsave(y_current->y_array[i]); | |
312 } | |
313 } | |
314 else | |
315 y_current->y_array = NULL; | |
316 return (void *)reg; | 316 return (void *)reg; |
317 } | 317 } |
318 | 318 |
319 /* | 319 /* |
320 * Put "reg" into register "name". Free any previous contents and "reg". | 320 * Put "reg" into register "name". Free any previous contents and "reg". |
714 static void | 714 static void |
715 put_reedit_in_typebuf(int silent) | 715 put_reedit_in_typebuf(int silent) |
716 { | 716 { |
717 char_u buf[3]; | 717 char_u buf[3]; |
718 | 718 |
719 if (restart_edit != NUL) | 719 if (restart_edit == NUL) |
720 { | 720 return; |
721 if (restart_edit == 'V') | 721 |
722 { | 722 if (restart_edit == 'V') |
723 buf[0] = 'g'; | 723 { |
724 buf[1] = 'R'; | 724 buf[0] = 'g'; |
725 buf[2] = NUL; | 725 buf[1] = 'R'; |
726 } | 726 buf[2] = NUL; |
727 else | 727 } |
728 { | 728 else |
729 buf[0] = restart_edit == 'I' ? 'i' : restart_edit; | 729 { |
730 buf[1] = NUL; | 730 buf[0] = restart_edit == 'I' ? 'i' : restart_edit; |
731 } | 731 buf[1] = NUL; |
732 if (ins_typebuf(buf, REMAP_NONE, 0, TRUE, silent) == OK) | 732 } |
733 restart_edit = NUL; | 733 if (ins_typebuf(buf, REMAP_NONE, 0, TRUE, silent) == OK) |
734 } | 734 restart_edit = NUL; |
735 } | 735 } |
736 | 736 |
737 /* | 737 /* |
738 * Insert register contents "s" into the typeahead buffer, so that it will be | 738 * Insert register contents "s" into the typeahead buffer, so that it will be |
739 * executed again. | 739 * executed again. |
1095 * Called for normal freeing and in case of error. | 1095 * Called for normal freeing and in case of error. |
1096 */ | 1096 */ |
1097 static void | 1097 static void |
1098 free_yank(long n) | 1098 free_yank(long n) |
1099 { | 1099 { |
1100 if (y_current->y_array != NULL) | 1100 if (y_current->y_array == NULL) |
1101 { | 1101 return; |
1102 long i; | 1102 |
1103 | 1103 long i; |
1104 for (i = n; --i >= 0; ) | 1104 |
1105 vim_free(y_current->y_array[i]); | 1105 for (i = n; --i >= 0; ) |
1106 VIM_CLEAR(y_current->y_array); | 1106 vim_free(y_current->y_array[i]); |
1107 } | 1107 VIM_CLEAR(y_current->y_array); |
1108 } | 1108 } |
1109 | 1109 |
1110 void | 1110 void |
1111 free_yank_all(void) | 1111 free_yank_all(void) |
1112 { | 1112 { |
2693 if (y_current->y_type == MLINE || i < y_current->y_size - 1) | 2693 if (y_current->y_type == MLINE || i < y_current->y_size - 1) |
2694 ++len; | 2694 ++len; |
2695 } | 2695 } |
2696 | 2696 |
2697 retval = alloc(len + 1); | 2697 retval = alloc(len + 1); |
2698 if (retval == NULL) | |
2699 return NULL; | |
2698 | 2700 |
2699 // Copy the lines of the yank register into the string. | 2701 // Copy the lines of the yank register into the string. |
2700 if (retval != NULL) | 2702 len = 0; |
2701 { | 2703 for (i = 0; i < y_current->y_size; ++i) |
2702 len = 0; | 2704 { |
2703 for (i = 0; i < y_current->y_size; ++i) | 2705 STRCPY(retval + len, y_current->y_array[i]); |
2704 { | 2706 len += (long)STRLEN(retval + len); |
2705 STRCPY(retval + len, y_current->y_array[i]); | 2707 |
2706 len += (long)STRLEN(retval + len); | 2708 // Insert a NL between lines and after the last line if y_type is |
2707 | 2709 // MLINE. |
2708 // Insert a NL between lines and after the last line if y_type is | 2710 if (y_current->y_type == MLINE || i < y_current->y_size - 1) |
2709 // MLINE. | 2711 retval[len++] = '\n'; |
2710 if (y_current->y_type == MLINE || i < y_current->y_size - 1) | 2712 } |
2711 retval[len++] = '\n'; | 2713 retval[len] = NUL; |
2712 } | |
2713 retval[len] = NUL; | |
2714 } | |
2715 | 2714 |
2716 return retval; | 2715 return retval; |
2717 } | 2716 } |
2718 | 2717 |
2719 static int | 2718 static int |