Mercurial > vim
diff src/time.c @ 31825:0d27ddce621d v9.0.1245
patch 9.0.1245: code is indented more than necessary
Commit: https://github.com/vim/vim/commit/032713f8299abd92fcfb1e490d1ae5c1ecadde41
Author: Yegappan Lakshmanan <yegappan@yahoo.com>
Date: Wed Jan 25 21:05:38 2023 +0000
patch 9.0.1245: 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 #11879)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Wed, 25 Jan 2023 22:15:03 +0100 |
parents | b6bef244837e |
children | 4545f58c8490 |
line wrap: on
line diff
--- a/src/time.c +++ b/src/time.c @@ -302,47 +302,48 @@ f_strftime(typval_T *argvars, typval_T * curtime = vim_localtime(&seconds, &tmval); // MSVC returns NULL for an invalid value of seconds. if (curtime == NULL) + { rettv->vval.v_string = vim_strsave((char_u *)_("(Invalid)")); - else - { + return; + } + # ifdef MSWIN - WCHAR result_buf[256]; - WCHAR *wp; + WCHAR result_buf[256]; + WCHAR *wp; - wp = enc_to_utf16(p, NULL); - if (wp != NULL) - (void)wcsftime(result_buf, ARRAY_LENGTH(result_buf), wp, curtime); - else - result_buf[0] = NUL; - rettv->vval.v_string = utf16_to_enc(result_buf, NULL); - vim_free(wp); + wp = enc_to_utf16(p, NULL); + if (wp != NULL) + (void)wcsftime(result_buf, ARRAY_LENGTH(result_buf), wp, curtime); + else + result_buf[0] = NUL; + rettv->vval.v_string = utf16_to_enc(result_buf, NULL); + vim_free(wp); # else - char_u result_buf[256]; - vimconv_T conv; - char_u *enc; + char_u result_buf[256]; + vimconv_T conv; + char_u *enc; - conv.vc_type = CONV_NONE; - enc = enc_locale(); - convert_setup(&conv, p_enc, enc); - if (conv.vc_type != CONV_NONE) - p = string_convert(&conv, p, NULL); - if (p == NULL || strftime((char *)result_buf, sizeof(result_buf), - (char *)p, curtime) == 0) - result_buf[0] = NUL; + conv.vc_type = CONV_NONE; + enc = enc_locale(); + convert_setup(&conv, p_enc, enc); + if (conv.vc_type != CONV_NONE) + p = string_convert(&conv, p, NULL); + if (p == NULL || strftime((char *)result_buf, sizeof(result_buf), + (char *)p, curtime) == 0) + result_buf[0] = NUL; - if (conv.vc_type != CONV_NONE) - vim_free(p); - convert_setup(&conv, enc, p_enc); - if (conv.vc_type != CONV_NONE) - rettv->vval.v_string = string_convert(&conv, result_buf, NULL); - else - rettv->vval.v_string = vim_strsave(result_buf); + if (conv.vc_type != CONV_NONE) + vim_free(p); + convert_setup(&conv, enc, p_enc); + if (conv.vc_type != CONV_NONE) + rettv->vval.v_string = string_convert(&conv, result_buf, NULL); + else + rettv->vval.v_string = vim_strsave(result_buf); - // Release conversion descriptors - convert_setup(&conv, NULL, NULL); - vim_free(enc); + // Release conversion descriptors + convert_setup(&conv, NULL, NULL); + vim_free(enc); # endif - } } # endif @@ -672,12 +673,12 @@ find_timer(long id) { timer_T *timer; - if (id >= 0) - { - FOR_ALL_TIMERS(timer) - if (timer->tr_id == id) - return timer; - } + if (id < 0) + return NULL; + + FOR_ALL_TIMERS(timer) + if (timer->tr_id == id) + return timer; return NULL; } @@ -791,7 +792,9 @@ timer_valid(timer_T *timer) { if (timer == NULL) return FALSE; - for (timer_T *t = first_timer; t != NULL; t = t->tr_next) + + timer_T *t; + FOR_ALL_TIMERS(t) if (t == timer) return TRUE; return FALSE; @@ -848,15 +851,16 @@ f_timer_pause(typval_T *argvars, typval_ return; if (argvars[0].v_type != VAR_NUMBER) + { emsg(_(e_number_expected)); - else - { - int paused = (int)tv_get_bool(&argvars[1]); + return; + } - timer = find_timer((int)tv_get_number(&argvars[0])); - if (timer != NULL) - timer->tr_paused = paused; - } + int paused = (int)tv_get_bool(&argvars[1]); + + timer = find_timer((int)tv_get_number(&argvars[0])); + if (timer != NULL) + timer->tr_paused = paused; } /* @@ -904,14 +908,14 @@ f_timer_start(typval_T *argvars, typval_ timer = create_timer(msec, repeat); if (timer == NULL) + { free_callback(&callback); - else - { - set_callback(&timer->tr_callback, &callback); - if (callback.cb_free_name) - vim_free(callback.cb_name); - rettv->vval.v_number = (varnumber_T)timer->tr_id; + return; } + set_callback(&timer->tr_callback, &callback); + if (callback.cb_free_name) + vim_free(callback.cb_name); + rettv->vval.v_number = (varnumber_T)timer->tr_id; } /* @@ -1019,28 +1023,28 @@ time_msg( static struct timeval start; struct timeval now; - if (time_fd != NULL) + if (time_fd == NULL) + return; + + if (strstr(mesg, "STARTING") != NULL) { - if (strstr(mesg, "STARTING") != NULL) - { - gettimeofday(&start, NULL); - prev_timeval = start; - fprintf(time_fd, "\n\ntimes in msec\n"); - fprintf(time_fd, " clock self+sourced self: sourced script\n"); - fprintf(time_fd, " clock elapsed: other lines\n\n"); - } - gettimeofday(&now, NULL); - time_diff(&start, &now); - if (((struct timeval *)tv_start) != NULL) - { - fprintf(time_fd, " "); - time_diff(((struct timeval *)tv_start), &now); - } + gettimeofday(&start, NULL); + prev_timeval = start; + fprintf(time_fd, "\n\ntimes in msec\n"); + fprintf(time_fd, " clock self+sourced self: sourced script\n"); + fprintf(time_fd, " clock elapsed: other lines\n\n"); + } + gettimeofday(&now, NULL); + time_diff(&start, &now); + if (((struct timeval *)tv_start) != NULL) + { fprintf(time_fd, " "); - time_diff(&prev_timeval, &now); - prev_timeval = now; - fprintf(time_fd, ": %s\n", mesg); + time_diff(((struct timeval *)tv_start), &now); } + fprintf(time_fd, " "); + time_diff(&prev_timeval, &now); + prev_timeval = now; + fprintf(time_fd, ": %s\n", mesg); } # endif // STARTUPTIME #endif // FEAT_EVAL