From: Mike Frysinger Date: Sun, 24 May 2009 06:26:19 +0000 (-0400) Subject: nvedit: speed up printing of environment X-Git-Tag: v2009.08-rc1~153^2~54 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=4c94f6c54bbc4dc5f418da01d8ec01e2adf636be;hp=3112030a430553768de5d30c05bedf8710784452;p=u-boot nvedit: speed up printing of environment The printing code would check the same environment byte multiple times and write to the console one byte at a time. For some devices (such as the Blackfin JTAG console which operates in 8 bytes at a time), this is pretty damned slow. So create a small 16 byte buffer to fill up and send to puts as needed. In the process, unify the different print functions, shrink the resulting code (source and compiled), and avoid excess env reads as those too can be somewhat expensive depending on the board. Signed-off-by: Mike Frysinger --- diff --git a/common/cmd_nvedit.c b/common/cmd_nvedit.c index 3ee971ab0e..ac9e5cfc32 100644 --- a/common/cmd_nvedit.c +++ b/common/cmd_nvedit.c @@ -94,56 +94,72 @@ int get_env_id (void) * Command interface: print one or all environment variables */ -int do_printenv (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) +/* + * state 0: finish printing this string and return (matched!) + * state 1: no matching to be done; print everything + * state 2: continue searching for matched name + */ +static int printenv(char *name, int state) { - int i, j, k, nxt; - int rcode = 0; - - if (argc == 1) { /* Print all env variables */ - for (i=0; env_get_char(i) != '\0'; i=nxt+1) { - for (nxt=i; env_get_char(nxt) != '\0'; ++nxt) - ; - for (k=i; k= 0) + state = 0; + + j = 0; + do { + buf[j++] = c = env_get_char(i++); + if (j == sizeof(buf) - 1) { + if (state <= 1) + puts(buf); + j = 0; } - } + } while (c != '\0'); - printf("\nEnvironment size: %d/%ld bytes\n", - i, (ulong)ENV_SIZE); + if (state <= 1) { + if (j) + puts(buf); + putc('\n'); + } - return 0; + if (ctrlc()) + return -1; } - for (i=1; i