public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: "Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>
To: "Jiri Slaby (SUSE)" <jirislaby@kernel.org>
Cc: gregkh@linuxfoundation.org, Kees Cook <keescook@chromium.org>,
	linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 08/11] tty: vt: simplify some unicode conditions
Date: Thu, 12 Jan 2023 11:52:14 +0200 (EET)	[thread overview]
Message-ID: <2a1c8867-92e9-edce-257e-89a343efe836@linux.intel.com> (raw)
In-Reply-To: <20230112080136.4929-8-jirislaby@kernel.org>

[-- Attachment #1: Type: text/plain, Size: 4152 bytes --]

On Thu, 12 Jan 2023, Jiri Slaby (SUSE) wrote:

> After previous patches, we can simply test vc->vc_uni_lines, so do so in
> many unicode functions. This makes the code more compact. And even use
>   if (!)
>     return;
> in vc_uniscr_scroll(), so that the whole code is indented on the left.
> 
> Signed-off-by: Jiri Slaby (SUSE) <jirislaby@kernel.org>
> ---
>  drivers/tty/vt/vt.c | 85 +++++++++++++++++++--------------------------
>  1 file changed, 36 insertions(+), 49 deletions(-)
> 
> diff --git a/drivers/tty/vt/vt.c b/drivers/tty/vt/vt.c
> index db72375141b0..74db07b32abe 100644
> --- a/drivers/tty/vt/vt.c
> +++ b/drivers/tty/vt/vt.c
> @@ -357,18 +357,14 @@ static void vc_uniscr_set(struct vc_data *vc, u32 **new_uni_lines)
>  
>  static void vc_uniscr_putc(struct vc_data *vc, u32 uc)
>  {
> -	u32 **uni_lines = vc->vc_uni_lines;
> -
> -	if (uni_lines)
> -		uni_lines[vc->state.y][vc->state.x] = uc;
> +	if (vc->vc_uni_lines)
> +		vc->vc_uni_lines[vc->state.y][vc->state.x] = uc;
>  }
>  
>  static void vc_uniscr_insert(struct vc_data *vc, unsigned int nr)
>  {
> -	u32 **uni_lines = vc->vc_uni_lines;
> -
> -	if (uni_lines) {
> -		u32 *ln = uni_lines[vc->state.y];
> +	if (vc->vc_uni_lines) {
> +		u32 *ln = vc->vc_uni_lines[vc->state.y];
>  		unsigned int x = vc->state.x, cols = vc->vc_cols;
>  
>  		memmove(&ln[x + nr], &ln[x], (cols - x - nr) * sizeof(*ln));
> @@ -378,10 +374,8 @@ static void vc_uniscr_insert(struct vc_data *vc, unsigned int nr)
>  
>  static void vc_uniscr_delete(struct vc_data *vc, unsigned int nr)
>  {
> -	u32 **uni_lines = vc->vc_uni_lines;
> -
> -	if (uni_lines) {
> -		u32 *ln = uni_lines[vc->state.y];
> +	if (vc->vc_uni_lines) {
> +		u32 *ln = vc->vc_uni_lines[vc->state.y];
>  		unsigned int x = vc->state.x, cols = vc->vc_cols;
>  
>  		memcpy(&ln[x], &ln[x + nr], (cols - x - nr) * sizeof(*ln));
> @@ -392,59 +386,52 @@ static void vc_uniscr_delete(struct vc_data *vc, unsigned int nr)
>  static void vc_uniscr_clear_line(struct vc_data *vc, unsigned int x,
>  				 unsigned int nr)
>  {
> -	u32 **uni_lines = vc->vc_uni_lines;
> -
> -	if (uni_lines) {
> -		u32 *ln = uni_lines[vc->state.y];
> -
> -		memset32(&ln[x], ' ', nr);
> -	}
> +	if (vc->vc_uni_lines)
> +		memset32(&vc->vc_uni_lines[vc->state.y][x], ' ', nr);
>  }
>  
>  static void vc_uniscr_clear_lines(struct vc_data *vc, unsigned int y,
>  				  unsigned int nr)
>  {
> -	u32 **uni_lines = vc->vc_uni_lines;
> -
> -	if (uni_lines) {
> -		unsigned int cols = vc->vc_cols;
> -
> +	if (vc->vc_uni_lines)
>  		while (nr--)
> -			memset32(uni_lines[y++], ' ', cols);
> -	}
> +			memset32(vc->vc_uni_lines[y++], ' ', vc->vc_cols);
>  }
>  
>  static void vc_uniscr_scroll(struct vc_data *vc, unsigned int t, unsigned int b,
>  			     enum con_scroll dir, unsigned int nr)
>  {
>  	u32 **uni_lines = vc->vc_uni_lines;
> +	unsigned int i, j, k, sz, d, clear;
>  
> -	if (uni_lines) {
> -		unsigned int i, j, k, sz, d, clear;
> +	if (!uni_lines)
> +		return;
>  
> -		sz = b - t;
> -		clear = b - nr;
> -		d = nr;
> -		if (dir == SM_DOWN) {
> -			clear = t;
> -			d = sz - nr;
> -		}
> -		for (i = 0; i < gcd(d, sz); i++) {
> -			u32 *tmp = uni_lines[t + i];
> -			j = i;
> -			while (1) {
> -				k = j + d;
> -				if (k >= sz)
> -					k -= sz;
> -				if (k == i)
> -					break;
> -				uni_lines[t + j] = uni_lines[t + k];
> -				j = k;
> -			}
> -			uni_lines[t + j] = tmp;
> +	sz = b - t;
> +	clear = b - nr;
> +	d = nr;
> +
> +	if (dir == SM_DOWN) {
> +		clear = t;
> +		d = sz - nr;
> +	}
> +
> +	for (i = 0; i < gcd(d, sz); i++) {
> +		u32 *tmp = uni_lines[t + i];
> +		j = i;
> +		while (1) {
> +			k = j + d;
> +			if (k >= sz)
> +				k -= sz;
> +			if (k == i)
> +				break;
> +			uni_lines[t + j] = uni_lines[t + k];
> +			j = k;
>  		}
> -		vc_uniscr_clear_lines(vc, clear, nr);
> +		uni_lines[t + j] = tmp;
>  	}
> +
> +	vc_uniscr_clear_lines(vc, clear, nr);
>  }
>  
>  static void vc_uniscr_copy_area(u32 **dst_lines,
> 

Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>

With the note that increased density of "vc[-_]" per line feels a step 
backwards on readability even if the number of lines is less, IMHO.

-- 
 i.

  reply	other threads:[~2023-01-12  9:55 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-12  8:01 [PATCH 01/11] tty: vt: remove vc_uniscr_debug_check() Jiri Slaby (SUSE)
2023-01-12  8:01 ` [PATCH 02/11] tty: vt: drop get_vc_uniscr() Jiri Slaby (SUSE)
2023-01-12  8:41   ` Ilpo Järvinen
2023-01-12  8:01 ` [PATCH 03/11] tty: vt: remove reference to undefined NO_VC_UNI_SCREEN Jiri Slaby (SUSE)
2023-01-12  8:44   ` Ilpo Järvinen
2023-01-12  8:01 ` [PATCH 04/11] tty: vt: use sizeof(*variable) where possible Jiri Slaby (SUSE)
2023-01-12  8:58   ` Ilpo Järvinen
2023-01-12  8:01 ` [PATCH 05/11] tty: vt: remove char32_t typedef Jiri Slaby (SUSE)
2023-01-12  8:52   ` Ilpo Järvinen
2023-01-12  9:34   ` Ilpo Järvinen
2023-01-12  8:01 ` [PATCH 06/11] tty: vt: remove struct uni_screen Jiri Slaby (SUSE)
2023-01-12  9:42   ` Ilpo Järvinen
2023-01-12  8:01 ` [PATCH 07/11] tty: vt: replace BUG_ON() by WARN_ON_ONCE() Jiri Slaby (SUSE)
2023-01-12  9:42   ` Ilpo Järvinen
2023-01-12  8:01 ` [PATCH 08/11] tty: vt: simplify some unicode conditions Jiri Slaby (SUSE)
2023-01-12  9:52   ` Ilpo Järvinen [this message]
2023-01-12  8:01 ` [PATCH 09/11] tty: vt: separate array juggling to juggle_array() Jiri Slaby (SUSE)
2023-01-12 10:15   ` Ilpo Järvinen
2023-01-12  8:01 ` [PATCH 10/11] tty: vt: saner names for more scroll variables Jiri Slaby (SUSE)
2023-01-12  9:59   ` Ilpo Järvinen
2023-01-12  8:01 ` [PATCH 11/11] tty: vt: cache row count in con_scroll() Jiri Slaby (SUSE)
2023-01-12 10:00   ` Ilpo Järvinen
2023-01-12  8:43 ` [PATCH 01/11] tty: vt: remove vc_uniscr_debug_check() Ilpo Järvinen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=2a1c8867-92e9-edce-257e-89a343efe836@linux.intel.com \
    --to=ilpo.jarvinen@linux.intel.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=jirislaby@kernel.org \
    --cc=keescook@chromium.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-serial@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox