mirror of
https://github.com/topjohnwu/ndk-busybox.git
synced 2024-11-27 05:30:34 +00:00
hush: speed up set_local_var
function old new delta set_local_var 265 290 +25
This commit is contained in:
parent
5e34ff29bc
commit
950bd72966
21
shell/hush.c
21
shell/hush.c
@ -1266,16 +1266,16 @@ static const char *get_local_var_value(const char *src)
|
|||||||
static int set_local_var(char *str, int flg_export, int flg_read_only)
|
static int set_local_var(char *str, int flg_export, int flg_read_only)
|
||||||
{
|
{
|
||||||
struct variable *cur;
|
struct variable *cur;
|
||||||
char *value;
|
char *eq_sign;
|
||||||
int name_len;
|
int name_len;
|
||||||
|
|
||||||
value = strchr(str, '=');
|
eq_sign = strchr(str, '=');
|
||||||
if (!value) { /* not expected to ever happen? */
|
if (!eq_sign) { /* not expected to ever happen? */
|
||||||
free(str);
|
free(str);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
name_len = value - str + 1; /* including '=' */
|
name_len = eq_sign - str + 1; /* including '=' */
|
||||||
cur = G.top_var; /* cannot be NULL (we have HUSH_VERSION and it's RO) */
|
cur = G.top_var; /* cannot be NULL (we have HUSH_VERSION and it's RO) */
|
||||||
while (1) {
|
while (1) {
|
||||||
if (strncmp(cur->varstr, str, name_len) != 0) {
|
if (strncmp(cur->varstr, str, name_len) != 0) {
|
||||||
@ -1288,7 +1288,6 @@ static int set_local_var(char *str, int flg_export, int flg_read_only)
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
/* We found an existing var with this name */
|
/* We found an existing var with this name */
|
||||||
*value = '\0';
|
|
||||||
if (cur->flg_read_only) {
|
if (cur->flg_read_only) {
|
||||||
#if !BB_MMU
|
#if !BB_MMU
|
||||||
if (!flg_read_only)
|
if (!flg_read_only)
|
||||||
@ -1297,11 +1296,13 @@ static int set_local_var(char *str, int flg_export, int flg_read_only)
|
|||||||
free(str);
|
free(str);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
//TODO: optimize out redundant unsetenv/putenv's?
|
if (flg_export == -1) {
|
||||||
debug_printf_env("%s: unsetenv '%s'\n", __func__, str);
|
debug_printf_env("%s: unsetenv '%s'\n", __func__, str);
|
||||||
unsetenv(str); /* just in case */
|
*eq_sign = '\0';
|
||||||
*value = '=';
|
unsetenv(str);
|
||||||
if (strcmp(cur->varstr, str) == 0) {
|
*eq_sign = '=';
|
||||||
|
}
|
||||||
|
if (strcmp(cur->varstr + name_len, eq_sign + 1) == 0) {
|
||||||
free_and_exp:
|
free_and_exp:
|
||||||
free(str);
|
free(str);
|
||||||
goto exp;
|
goto exp;
|
||||||
|
Loading…
Reference in New Issue
Block a user