2022-06-14 08:38:09

by Jiri Slaby

[permalink] [raw]
Subject: [PATCH 4/7] tty/vt: consolemap: saner variable names in set_inverse_transl()

The function uses too vague variable names like i, j, k for iterators, p,
q, p1, p2 for pointers etc.

Rename all these, so that it is clear what is going on:
- dict: for dictionaries.
- d, r, g: for dir, row, glyph iterators -- these are unsigned now.
- dir, row: for directory and row pointers.
- glyph: for the glyph.
- and so on...

This is a lot of shuffling, but the result pays off, IMO.

Signed-off-by: Jiri Slaby <[email protected]>
---
drivers/tty/vt/consolemap.c | 26 +++++++++++++-------------
1 file changed, 13 insertions(+), 13 deletions(-)

diff --git a/drivers/tty/vt/consolemap.c b/drivers/tty/vt/consolemap.c
index a69dfda8e3d0..3d0e10dac6d9 100644
--- a/drivers/tty/vt/consolemap.c
+++ b/drivers/tty/vt/consolemap.c
@@ -214,29 +214,29 @@ struct uni_pagedict {

static struct uni_pagedict *dflt;

-static void set_inverse_transl(struct vc_data *conp, struct uni_pagedict *p,
+static void set_inverse_transl(struct vc_data *conp, struct uni_pagedict *dict,
enum translation_map m)
{
- int j, glyph;
unsigned short *t = translations[m];
- unsigned char *q;
+ unsigned char *inv;

- if (!p)
+ if (!dict)
return;
- q = p->inverse_translations[m];
+ inv = dict->inverse_translations[m];

- if (!q) {
- q = p->inverse_translations[m] = kmalloc(MAX_GLYPH, GFP_KERNEL);
- if (!q)
+ if (!inv) {
+ inv = dict->inverse_translations[m] = kmalloc(MAX_GLYPH,
+ GFP_KERNEL);
+ if (!inv)
return;
}
- memset(q, 0, MAX_GLYPH);
+ memset(inv, 0, MAX_GLYPH);

- for (j = 0; j < ARRAY_SIZE(translations[i]); j++) {
- glyph = conv_uni_to_pc(conp, t[j]);
- if (glyph >= 0 && glyph < MAX_GLYPH && q[glyph] < 32) {
+ for (unsigned int ch = 0; ch < ARRAY_SIZE(translations[m]); ch++) {
+ int glyph = conv_uni_to_pc(conp, t[ch]);
+ if (glyph >= 0 && glyph < MAX_GLYPH && inv[glyph] < 32) {
/* prefer '-' above SHY etc. */
- q[glyph] = j;
+ inv[glyph] = ch;
}
}
}
--
2.36.1


2022-06-14 08:42:19

by Jiri Slaby

[permalink] [raw]
Subject: Re: [PATCH 4/7] tty/vt: consolemap: saner variable names in set_inverse_transl()

On 14. 06. 22, 10:35, Ilpo Järvinen wrote:
>> + for (unsigned int ch = 0; ch < ARRAY_SIZE(translations[m]); ch++) {
>
> This removes the compile error you introduced earlier. Other than that:

Bah, let me fix that up. It's an error coming from a rebase -- I rebased
this on the current tty-next as this was part of v2 of the previous
series which Greg already applied 8-).

thanks,
--
js
suse labs

2022-06-14 09:09:50

by Ilpo Järvinen

[permalink] [raw]
Subject: Re: [PATCH 4/7] tty/vt: consolemap: saner variable names in set_inverse_transl()

On Tue, 14 Jun 2022, Jiri Slaby wrote:

> The function uses too vague variable names like i, j, k for iterators, p,
> q, p1, p2 for pointers etc.
>
> Rename all these, so that it is clear what is going on:
> - dict: for dictionaries.
> - d, r, g: for dir, row, glyph iterators -- these are unsigned now.
> - dir, row: for directory and row pointers.
> - glyph: for the glyph.
> - and so on...
>
> This is a lot of shuffling, but the result pays off, IMO.
>
> Signed-off-by: Jiri Slaby <[email protected]>
> ---
> drivers/tty/vt/consolemap.c | 26 +++++++++++++-------------
> 1 file changed, 13 insertions(+), 13 deletions(-)
>
> diff --git a/drivers/tty/vt/consolemap.c b/drivers/tty/vt/consolemap.c
> index a69dfda8e3d0..3d0e10dac6d9 100644
> --- a/drivers/tty/vt/consolemap.c
> +++ b/drivers/tty/vt/consolemap.c
> @@ -214,29 +214,29 @@ struct uni_pagedict {
>
> static struct uni_pagedict *dflt;
>
> -static void set_inverse_transl(struct vc_data *conp, struct uni_pagedict *p,
> +static void set_inverse_transl(struct vc_data *conp, struct uni_pagedict *dict,
> enum translation_map m)
> {
> - int j, glyph;
> unsigned short *t = translations[m];
> - unsigned char *q;
> + unsigned char *inv;
>
> - if (!p)
> + if (!dict)
> return;
> - q = p->inverse_translations[m];
> + inv = dict->inverse_translations[m];
>
> - if (!q) {
> - q = p->inverse_translations[m] = kmalloc(MAX_GLYPH, GFP_KERNEL);
> - if (!q)
> + if (!inv) {
> + inv = dict->inverse_translations[m] = kmalloc(MAX_GLYPH,
> + GFP_KERNEL);
> + if (!inv)
> return;
> }
> - memset(q, 0, MAX_GLYPH);
> + memset(inv, 0, MAX_GLYPH);
>
> - for (j = 0; j < ARRAY_SIZE(translations[i]); j++) {
> - glyph = conv_uni_to_pc(conp, t[j]);
> - if (glyph >= 0 && glyph < MAX_GLYPH && q[glyph] < 32) {
> + for (unsigned int ch = 0; ch < ARRAY_SIZE(translations[m]); ch++) {

This removes the compile error you introduced earlier. Other than that:

Reviewed-by: Ilpo J?rvinen <[email protected]>

> + int glyph = conv_uni_to_pc(conp, t[ch]);
> + if (glyph >= 0 && glyph < MAX_GLYPH && inv[glyph] < 32) {
> /* prefer '-' above SHY etc. */
> - q[glyph] = j;
> + inv[glyph] = ch;
> }
> }
> }
>

--
i.