summaryrefslogtreecommitdiff
path: root/common/console.c
diff options
context:
space:
mode:
authorVincent Palatin <vpalatin@chromium.org>2012-05-15 00:41:54 +0000
committerVincent Palatin <vpalatin@chromium.org>2012-05-15 01:32:44 +0000
commit33b03d5a39e7a09a41ba7f6d5d7ff4c1875a3cb1 (patch)
treef154477680d64625e98d64e12d275c14c82725d2 /common/console.c
parent35b1b7bf907ea9ffedc1c0134d5be9488ff1dd70 (diff)
downloadchrome-ec-33b03d5a39e7a09a41ba7f6d5d7ff4c1875a3cb1.tar.gz
Sort console commands at build time
Use the linker to sort console commands by name, this saves execution time and memory. BUG=none TEST=generate several images with 5N, 5N+1, 5N-1 commands and check the output of the "help" command. Change-Id: Ib5d8f3bca726621c68ab152f4fa662cee355abb1 Signed-off-by: Vincent Palatin <vpalatin@chromium.org>
Diffstat (limited to 'common/console.c')
-rw-r--r--common/console.c25
1 files changed, 4 insertions, 21 deletions
diff --git a/common/console.c b/common/console.c
index 3a57716db3..cebfd573c9 100644
--- a/common/console.c
+++ b/common/console.c
@@ -227,36 +227,19 @@ void console_task(void)
static int command_help(int argc, char **argv)
{
const int ncmds = __cmds_end - __cmds;
- int i, j, cols, rows;
- unsigned char indices[ncmds];
-
- /* Initialize the index. */
- for (i = 0; i < ncmds; i++)
- indices[i] = i;
-
- /* Bubble sort commands by name. */
- for (i = 0; i < (ncmds - 1); i++) {
- for (j = i + 1; j < ncmds; j++) {
- if (strcasecmp(__cmds[indices[i]].name,
- __cmds[indices[j]].name) > 0) {
- int tmp = indices[j];
- indices[j] = indices[i];
- indices[i] = tmp;
- }
- }
- }
+ const int cols = 5; /* printing in five columns */
+ const int rows = (ncmds + cols - 1) / cols;
+ int i, j;
ccputs("Known commands:\n");
- cols = 5; /* printing in five columns */
- rows = (ncmds + 1) / cols;
for (i = 0; i < rows; i++) {
ccputs(" ");
for (j = 0; j < cols; j++) {
int index = j * rows + i;
if (index >= ncmds)
break;
- ccprintf("%-15s", __cmds[indices[index]].name);
+ ccprintf("%-15s", __cmds[index].name);
}
ccputs("\n");
cflush();