public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* Re: [patch 3/2] drivers/char/vt.c: remove unnecessary code
@ 2005-02-28 15:06 colbuse
  2005-02-28 16:44 ` Stelian Pop
  0 siblings, 1 reply; 18+ messages in thread
From: colbuse @ 2005-02-28 15:06 UTC (permalink / raw)
  To: linux-kernel, arjan




>> - for(npar = 0 ; npar < NPAR ; npar++)
>> + for(npar = NPAR - 1; npar >= 0; npar--)
>> par[npar] = 0;

>if you really want to clean this up.. 

Well, actually, I was not myself entirely convinced about it... This is the
reason for I wrote "please _don't_ apply this, but tell me what you think about
it.".

>why not use memset() instead ?

Because I simply didn't thought to it :-) .

Hey, that makes fully sense! So far I know, memset() is quicker than 
(or as quick as) a loop, and it remains fully readable (in my opinion :).

Well, such a patch would be : 

--- drivers/char/vt.c   2004-12-24 22:35:25.000000000 +0100
+++ drivers/char/vt2.c  2005-02-28 15:55:11.782717810 +0100
@@ -1655,8 +1655,8 @@
                        vc_state = ESnormal;
                return;
        case ESsquare:
-               for(npar = 0 ; npar < NPAR ; npar++)
-                       par[npar] = 0;
+               /* Setting par[]'s elems at 0.  */
+               memset(par, 0, NPAR*sizeof(unsigned int));
                npar = 0;
                vc_state = ESgetpars;
                if (c == '[') { /* Function key */


Thank you for the suggestion.
What do you think of this one?

(Please note that I'm not trying to get a patch for it _by force_ into the
kernel. If it's a bad idea, let's let thing like they currently are, 
the current loop just works.)

cu

--
Emmanuel Colbus
Club GNU/Linux
ENSIMAG - Departement telecoms

-------------------------------------------------
envoyé via Webmail/IMAG !


^ permalink raw reply	[flat|nested] 18+ messages in thread
* Re: [patch 3/2] drivers/char/vt.c: remove unnecessary code
@ 2005-02-28 13:13 colbuse
  2005-02-28 13:28 ` Russell King
                   ` (2 more replies)
  0 siblings, 3 replies; 18+ messages in thread
From: colbuse @ 2005-02-28 13:13 UTC (permalink / raw)
  To: linux-kernel; +Cc: akpm


>On Mon, Feb 28, 2005 at 01:57:59PM +0100, colbuse@xxxxxxxxxxxxxxx wrote:
>> Please _don't_ apply this, but tell me what you think about it.

>It's broken. 8)

>> --- old/drivers/char/vt.c 2004-12-24 22:35:25.000000000 +0100
>> +++ new/drivers/char/vt.c 2005-02-28 12:53:57.933256631 +0100
>> @@ -1655,9 +1655,9 @@
>> vc_state = ESnormal;
>> return;
>> case ESsquare:
>> - for(npar = 0 ; npar < NPAR ; npar++)
>> + for(npar = NPAR-1; npar < NPAR; npar--)

>How many times do you want this for loop to run?


NPAR times :-). As I stated, npar is unsigned.


See : 
$cat x.c
#include <stdio.h>
#define NPAR 5

int main(void){
        unsigned int i;
        int j=0;
        for(i=NPAR-1;i<NPAR;i--) j++;
        fprintf(stdout,"it has runned %d times :-)\n",j);
}

$gcc x.c -o x && ./x
it has runned 5 times :-)
$

--
Emmanuel Colbus
Club GNU/Linux
ENSIMAG - Departement telecoms

-------------------------------------------------
envoyé via Webmail/IMAG !


^ permalink raw reply	[flat|nested] 18+ messages in thread
* [patch 3/2] drivers/char/vt.c: remove unnecessary code
@ 2005-02-28 12:57 colbuse
  2005-02-28 13:02 ` Russell King
  2005-02-28 13:33 ` linux-os
  0 siblings, 2 replies; 18+ messages in thread
From: colbuse @ 2005-02-28 12:57 UTC (permalink / raw)
  To: linux-kernel; +Cc: akpm



We could change an affectation into an incrementation by this patch, and,
so far I know, incrementing is quicker than or as quick as setting
a variable (depends on the architecture).

Please _don't_ apply this, but tell me what you think about it.
Note that npar is unsigned.

Signed-off-by: Emmanuel Colbus <emmanuel.colbus@ensimag.imag.fr>

--- old/drivers/char/vt.c       2004-12-24 22:35:25.000000000 +0100
+++ new/drivers/char/vt.c       2005-02-28 12:53:57.933256631 +0100
@@ -1655,9 +1655,9 @@
                        vc_state = ESnormal;
                return;
        case ESsquare:
-               for(npar = 0 ; npar < NPAR ; npar++)
+               for(npar = NPAR-1; npar < NPAR; npar--)
                        par[npar] = 0;
+               npar++;
-               npar = 0;
                vc_state = ESgetpars;
                if (c == '[') { /* Function key */
                        vc_state=ESfunckey;


--
Emmanuel Colbus
Club GNU/Linux
ENSIMAG - departement telecoms


-------------------------------------------------
envoyé via Webmail/IMAG !


^ permalink raw reply	[flat|nested] 18+ messages in thread

end of thread, other threads:[~2005-02-28 20:30 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-02-28 15:06 [patch 3/2] drivers/char/vt.c: remove unnecessary code colbuse
2005-02-28 16:44 ` Stelian Pop
2005-02-28 17:29   ` emmanuel.colbus@ensimag.imag.fr
2005-02-28 19:18     ` Stelian Pop
2005-02-28 20:30     ` Adrian Bunk
  -- strict thread matches above, loose matches on Subject: below --
2005-02-28 13:13 colbuse
2005-02-28 13:28 ` Russell King
2005-02-28 14:01   ` colbuse
2005-02-28 14:22     ` Arjan van de Ven
2005-02-28 14:43     ` Martin Mares
2005-02-28 14:57     ` Horst von Brand
2005-02-28 13:32 ` Adrian Bunk
2005-02-28 13:48 ` Dmitry Torokhov
2005-02-28 14:02   ` Arjan van de Ven
2005-02-28 14:06     ` Dmitry Torokhov
2005-02-28 12:57 colbuse
2005-02-28 13:02 ` Russell King
2005-02-28 13:33 ` linux-os

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox