mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Frederic Weisbecker <fweisbec@gmail.com>
To: "André Goddard Rosa" <andre.goddard@gmail.com>
Cc: laijs@cn.fujitsu.com, mingo@elte.hu, davem@davemloft.net,
	akpm@linux-foundation.org, harvey.harrison@gmail.com,
	linux list <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v2 6/7] vsprintf: move local vars to block local vars and remove unneeded ones
Date: Mon, 2 Nov 2009 19:52:52 +0100	[thread overview]
Message-ID: <20091102185249.GB4880@nowhere> (raw)
In-Reply-To: <b8bf37780911020926p2c9e0fccva255c003b563c3ed@mail.gmail.com>

On Mon, Nov 02, 2009 at 03:26:48PM -0200, André Goddard Rosa wrote:
> From 636fc10ec894c83ba3b73433fee6df94529bc930 Mon Sep 17 00:00:00 2001
> From: =?UTF-8?q?Andr=C3=A9=20Goddard=20Rosa?= <andre.goddard@gmail.com>
> Date: Sun, 1 Nov 2009 14:04:37 -0200
> Subject: [PATCH v2 6/7] vsprintf: move local vars to block local vars
> and remove unneeded ones
> MIME-Version: 1.0
> Content-Type: text/plain; charset=UTF-8
> Content-Transfer-Encoding: 8bit
> 
> It also decreases code size:
>    text    data     bss     dec     hex filename
>   15719       0       8   15727    3d6f lib/vsprintf.o-before
>   15703       0       8   15711    3d5f lib/vsprintf.o-after



Actually, moving variable scope from function local to block
local is nice for code reviewing, it increases the code readability.
And this is a more important impact than binary code size IMO.


 
> @@ -1616,7 +1609,9 @@ int bstr_printf(char *buf, size_t size, const
> char *fmt, const u32 *bin_buf)
>  			spec.precision = get_arg(int);
>  			break;
> 
> -		case FORMAT_TYPE_CHAR:
> +		case FORMAT_TYPE_CHAR: {
> +			char c;
> +
>  			if (!(spec.flags & LEFT)) {
>  				while (--spec.field_width > 0) {
>  					if (str < end)
> @@ -1634,11 +1629,11 @@ int bstr_printf(char *buf, size_t size, const
> char *fmt, const u32 *bin_buf)
>  				++str;
>  			}
>  			break;
> +		}
> 
>  		case FORMAT_TYPE_STR: {
>  			const char *str_arg = args;
> -			size_t len = strlen(str_arg);
> -			args += len + 1;
> +			args += strlen(str_arg) + 1;
>  			str = string(str, end, (char *)str_arg, spec);
>  			break;
>  		}
> @@ -1655,6 +1650,10 @@ int bstr_printf(char *buf, size_t size, const
> char *fmt, const u32 *bin_buf)
>  			++str;
>  			break;
> 
> +		/*
> +		 * Merging this handling with the above one increases code size!
> +		 * Why, gcc, why?!
> +		 */
>  		case FORMAT_TYPE_INVALID:



Please do this merge:

@@ -1633,11 +1633,6 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
                        break;
 
                case FORMAT_TYPE_PERCENT_CHAR:
-                       if (str < end)
-                               *str = '%';
-                       ++str;
-                       break;
-
                case FORMAT_TYPE_INVALID:
                        if (str < end)
                                *str = '%';

We don't care that much about binary code size in vsprintf.c
Code readability has a really higher priority over binary code size
here.


The rest looks good.


      reply	other threads:[~2009-11-02 18:52 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-11-02 17:26 André Goddard Rosa
2009-11-02 18:52 ` Frederic Weisbecker [this message]

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=20091102185249.GB4880@nowhere \
    --to=fweisbec@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=andre.goddard@gmail.com \
    --cc=davem@davemloft.net \
    --cc=harvey.harrison@gmail.com \
    --cc=laijs@cn.fujitsu.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    /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

all inboxes | Powered by JetHome®