vt: deduplicate setGx code
The code for setting G0 and G1 is duplicated -- for each of them. Move the code to a separate function (vc_setGx) and distinguish the two cases by a parameter. Change if-else-if to switch which allows for slightly better optimization (decision tree). Signed-off-by: Jiri Slaby <jslaby@suse.cz> Link: https://lore.kernel.org/r/20200615074910.19267-4-jslaby@suse.cz Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
parent
77bc14f273
commit
b4d92b6575
@ -2103,6 +2103,30 @@ static void reset_terminal(struct vc_data *vc, int do_clear)
|
|||||||
csi_J(vc, 2);
|
csi_J(vc, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void vc_setGx(struct vc_data *vc, unsigned int which, int c)
|
||||||
|
{
|
||||||
|
unsigned char *charset = which == 0 ? &vc->state.G0_charset :
|
||||||
|
&vc->state.G1_charset;
|
||||||
|
|
||||||
|
switch (c) {
|
||||||
|
case '0':
|
||||||
|
*charset = GRAF_MAP;
|
||||||
|
break;
|
||||||
|
case 'B':
|
||||||
|
*charset = LAT1_MAP;
|
||||||
|
break;
|
||||||
|
case 'U':
|
||||||
|
*charset = IBMPC_MAP;
|
||||||
|
break;
|
||||||
|
case 'K':
|
||||||
|
*charset = USER_MAP;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (vc->state.charset == which)
|
||||||
|
vc->vc_translate = set_translate(*charset, vc);
|
||||||
|
}
|
||||||
|
|
||||||
/* console_lock is held */
|
/* console_lock is held */
|
||||||
static void do_con_trol(struct tty_struct *tty, struct vc_data *vc, int c)
|
static void do_con_trol(struct tty_struct *tty, struct vc_data *vc, int c)
|
||||||
{
|
{
|
||||||
@ -2485,29 +2509,11 @@ static void do_con_trol(struct tty_struct *tty, struct vc_data *vc, int c)
|
|||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
case ESsetG0:
|
case ESsetG0:
|
||||||
if (c == '0')
|
vc_setGx(vc, 0, c);
|
||||||
vc->state.G0_charset = GRAF_MAP;
|
|
||||||
else if (c == 'B')
|
|
||||||
vc->state.G0_charset = LAT1_MAP;
|
|
||||||
else if (c == 'U')
|
|
||||||
vc->state.G0_charset = IBMPC_MAP;
|
|
||||||
else if (c == 'K')
|
|
||||||
vc->state.G0_charset = USER_MAP;
|
|
||||||
if (vc->state.charset == 0)
|
|
||||||
vc->vc_translate = set_translate(vc->state.G0_charset, vc);
|
|
||||||
vc->vc_state = ESnormal;
|
vc->vc_state = ESnormal;
|
||||||
return;
|
return;
|
||||||
case ESsetG1:
|
case ESsetG1:
|
||||||
if (c == '0')
|
vc_setGx(vc, 1, c);
|
||||||
vc->state.G1_charset = GRAF_MAP;
|
|
||||||
else if (c == 'B')
|
|
||||||
vc->state.G1_charset = LAT1_MAP;
|
|
||||||
else if (c == 'U')
|
|
||||||
vc->state.G1_charset = IBMPC_MAP;
|
|
||||||
else if (c == 'K')
|
|
||||||
vc->state.G1_charset = USER_MAP;
|
|
||||||
if (vc->state.charset == 1)
|
|
||||||
vc->vc_translate = set_translate(vc->state.G1_charset, vc);
|
|
||||||
vc->vc_state = ESnormal;
|
vc->vc_state = ESnormal;
|
||||||
return;
|
return;
|
||||||
case ESosc:
|
case ESosc:
|
||||||
|
Loading…
Reference in New Issue
Block a user