0
0
mirror of https://github.com/vim/vim.git synced 2025-09-28 04:24:06 -04:00

patch 8.2.3879: getreg() and getregtype() contain dead code

Problem:    getreg() and getregtype() contain dead code.
Solution:   Remove the needless check. (closes #9392)  Also refactor to put
            common code in a shared function.
This commit is contained in:
Bram Moolenaar
2021-12-24 10:48:30 +00:00
parent 310091d20f
commit 51e64b2789
2 changed files with 49 additions and 48 deletions

View File

@@ -4674,17 +4674,43 @@ f_getpos(typval_T *argvars, typval_T *rettv)
getpos_both(argvars, rettv, FALSE, FALSE); getpos_both(argvars, rettv, FALSE, FALSE);
} }
/*
* Common between getreg() and getregtype(): get the register name from the
* first argument.
* Returns zero on error.
*/
static int
getreg_get_regname(typval_T *argvars)
{
char_u *strregname;
if (argvars[0].v_type != VAR_UNKNOWN)
{
strregname = tv_get_string_chk(&argvars[0]);
if (strregname != NULL && in_vim9script() && STRLEN(strregname) > 1)
{
semsg(_(e_register_name_must_be_one_char_str), strregname);
strregname = NULL;
}
if (strregname == NULL) // type error; errmsg already given
return 0;
}
else
// Default to v:register
strregname = get_vim_var_str(VV_REG);
return *strregname == 0 ? '"' : *strregname;
}
/* /*
* "getreg()" function * "getreg()" function
*/ */
static void static void
f_getreg(typval_T *argvars, typval_T *rettv) f_getreg(typval_T *argvars, typval_T *rettv)
{ {
char_u *strregname;
int regname; int regname;
int arg2 = FALSE; int arg2 = FALSE;
int return_list = FALSE; int return_list = FALSE;
int error = FALSE;
if (in_vim9script() if (in_vim9script()
&& (check_for_opt_string_arg(argvars, 0) == FAIL && (check_for_opt_string_arg(argvars, 0) == FAIL
@@ -4694,32 +4720,21 @@ f_getreg(typval_T *argvars, typval_T *rettv)
&& check_for_opt_bool_arg(argvars, 2) == FAIL))))) && check_for_opt_bool_arg(argvars, 2) == FAIL)))))
return; return;
if (argvars[0].v_type != VAR_UNKNOWN) regname = getreg_get_regname(argvars);
{ if (regname == 0)
strregname = tv_get_string_chk(&argvars[0]);
if (strregname == NULL)
error = TRUE;
else if (in_vim9script() && STRLEN(strregname) > 1)
{
semsg(_(e_register_name_must_be_one_char_str), strregname);
error = TRUE;
}
if (argvars[1].v_type != VAR_UNKNOWN)
{
arg2 = (int)tv_get_bool_chk(&argvars[1], &error);
if (!error && argvars[2].v_type != VAR_UNKNOWN)
return_list = (int)tv_get_bool_chk(&argvars[2], &error);
}
}
else
strregname = get_vim_var_str(VV_REG);
if (error)
return; return;
regname = (strregname == NULL ? '"' : *strregname); if (argvars[0].v_type != VAR_UNKNOWN && argvars[1].v_type != VAR_UNKNOWN)
if (regname == 0) {
regname = '"'; int error = FALSE;
arg2 = (int)tv_get_bool_chk(&argvars[1], &error);
if (!error && argvars[2].v_type != VAR_UNKNOWN)
return_list = (int)tv_get_bool_chk(&argvars[2], &error);
if (error)
return;
}
if (return_list) if (return_list)
{ {
@@ -4745,36 +4760,20 @@ f_getreg(typval_T *argvars, typval_T *rettv)
static void static void
f_getregtype(typval_T *argvars, typval_T *rettv) f_getregtype(typval_T *argvars, typval_T *rettv)
{ {
char_u *strregname;
int regname; int regname;
char_u buf[NUMBUFLEN + 2]; char_u buf[NUMBUFLEN + 2];
long reglen = 0; long reglen = 0;
// on error return an empty string
rettv->v_type = VAR_STRING;
rettv->vval.v_string = NULL;
if (in_vim9script() && check_for_opt_string_arg(argvars, 0) == FAIL) if (in_vim9script() && check_for_opt_string_arg(argvars, 0) == FAIL)
return; return;
if (argvars[0].v_type != VAR_UNKNOWN) regname = getreg_get_regname(argvars);
{
strregname = tv_get_string_chk(&argvars[0]);
if (strregname != NULL && in_vim9script() && STRLEN(strregname) > 1)
{
semsg(_(e_register_name_must_be_one_char_str), strregname);
strregname = NULL;
}
if (strregname == NULL) // type error; errmsg already given
{
rettv->v_type = VAR_STRING;
rettv->vval.v_string = NULL;
return;
}
}
else
// Default to v:register
strregname = get_vim_var_str(VV_REG);
regname = (strregname == NULL ? '"' : *strregname);
if (regname == 0) if (regname == 0)
regname = '"'; return;
buf[0] = NUL; buf[0] = NUL;
buf[1] = NUL; buf[1] = NUL;

View File

@@ -749,6 +749,8 @@ static char *(features[]) =
static int included_patches[] = static int included_patches[] =
{ /* Add new patch number below this line */ { /* Add new patch number below this line */
/**/
3879,
/**/ /**/
3878, 3878,
/**/ /**/