mirror of
https://github.com/MaJerle/lwshell.git
synced 2025-02-06 13:08:22 +08:00
Optimize for speed
This commit is contained in:
parent
3ca845f2de
commit
6f475afcae
@ -136,7 +136,7 @@ prv_parse_input(lwshell_t* lw) {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
lw->argv[lw->argc++] = str; /* Set start of argument directly on character */
|
lw->argv[lw->argc++] = str; /* Set start of argument directly on character */
|
||||||
while ((*str != ' ' && *str != '\0')) {
|
while (*str != ' ' && *str != '\0') {
|
||||||
if (*str == '"') { /* Quote should not be here... */
|
if (*str == '"') { /* Quote should not be here... */
|
||||||
*str = '\0'; /* ...add NULL termination to end token */
|
*str = '\0'; /* ...add NULL termination to end token */
|
||||||
}
|
}
|
||||||
@ -155,10 +155,12 @@ prv_parse_input(lwshell_t* lw) {
|
|||||||
/* Check for command */
|
/* Check for command */
|
||||||
if (lw->argc > 0 && cmds_cnt > 0) {
|
if (lw->argc > 0 && cmds_cnt > 0) {
|
||||||
lwshell_cmd_t* c = NULL;
|
lwshell_cmd_t* c = NULL;
|
||||||
|
size_t arg_len = strlen(lw->argv[0]);
|
||||||
|
|
||||||
/* Process all commands */
|
/* Process all commands */
|
||||||
for (size_t i = 0; i < cmds_cnt; ++i) {
|
for (size_t i = 0; i < cmds_cnt; ++i) {
|
||||||
if (strlen(lw->argv[0]) == strlen(cmds[i].name)
|
if (arg_len == strlen(cmds[i].name)
|
||||||
&& strncmp(cmds[i].name, lw->argv[0], strlen(lw->argv[0])) == 0) {
|
&& strncmp(cmds[i].name, lw->argv[0], arg_len) == 0) {
|
||||||
c = &cmds[i];
|
c = &cmds[i];
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user