Patchwork [U-Boot,2/2] cmd_nand: slight optimization of nand_dump function

login
register
mail settings
Submitter Masahiro Yamada
Date July 11, 2013, 8:27 a.m.
Message ID <1373531233-31976-3-git-send-email-yamada.m@jp.panasonic.com>
Download mbox | patch
Permalink /patch/258325/
State Accepted
Delegated to: Scott Wood
Headers show

Comments

Masahiro Yamada - July 11, 2013, 8:27 a.m.
If a non-zero value is given to only_oob argument,
printing the main area is skipped.

With a little modification, we can skip the whole
while loop.

Signed-off-by: Masahiro Yamada <yamada.m@jp.panasonic.com>
---
 common/cmd_nand.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)
Scott Wood - Aug. 13, 2013, 9:40 p.m.
On Thu, 2013-07-11 at 17:27 +0900, Masahiro Yamada wrote:
> If a non-zero value is given to only_oob argument,
> printing the main area is skipped.
> 
> With a little modification, we can skip the whole
> while loop.
> 
> Signed-off-by: Masahiro Yamada <yamada.m@jp.panasonic.com>
> ---
>  common/cmd_nand.c | 13 ++++++++-----
>  1 file changed, 8 insertions(+), 5 deletions(-)
> 
> diff --git a/common/cmd_nand.c b/common/cmd_nand.c
> index a66f569..adc1ce4 100644
> --- a/common/cmd_nand.c
> +++ b/common/cmd_nand.c
> @@ -77,18 +77,21 @@ static int nand_dump(nand_info_t *nand, ulong off, int only_oob, int repeat)
>  		goto free_all;
>  	}
>  	printf("Page %08lx dump:\n", off);
> -	i = nand->writesize >> 4;
> -	p = datbuf;
>  
> -	while (i--) {
> -		if (!only_oob)
> +	if (!only_oob) {
> +		i = nand->writesize >> 4;
> +		p = datbuf;
> +
> +		while (i--) {
>  			printf("\t%02x %02x %02x %02x %02x %02x %02x %02x"
>  			       "  %02x %02x %02x %02x %02x %02x %02x %02x\n",
>  			       p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7],
>  			       p[8], p[9], p[10], p[11], p[12], p[13], p[14],
>  			       p[15]);
> -		p += 16;
> +			p += 16;
> +		}
>  	}
> +
>  	puts("OOB:\n");
>  	i = nand->oobsize >> 3;
>  	p = oobbuf;

I'll probably apply this since it makes the code slightly more
intuitive, but as an optimization I doubt this makes any noticeable
difference.

-Scott

Patch

diff --git a/common/cmd_nand.c b/common/cmd_nand.c
index a66f569..adc1ce4 100644
--- a/common/cmd_nand.c
+++ b/common/cmd_nand.c
@@ -77,18 +77,21 @@  static int nand_dump(nand_info_t *nand, ulong off, int only_oob, int repeat)
 		goto free_all;
 	}
 	printf("Page %08lx dump:\n", off);
-	i = nand->writesize >> 4;
-	p = datbuf;
 
-	while (i--) {
-		if (!only_oob)
+	if (!only_oob) {
+		i = nand->writesize >> 4;
+		p = datbuf;
+
+		while (i--) {
 			printf("\t%02x %02x %02x %02x %02x %02x %02x %02x"
 			       "  %02x %02x %02x %02x %02x %02x %02x %02x\n",
 			       p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7],
 			       p[8], p[9], p[10], p[11], p[12], p[13], p[14],
 			       p[15]);
-		p += 16;
+			p += 16;
+		}
 	}
+
 	puts("OOB:\n");
 	i = nand->oobsize >> 3;
 	p = oobbuf;