diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2009-04-21 11:23:56 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2009-04-21 11:23:56 +0000 |
commit | 950bd729665cecf1fbee65bc6e57e087c93aaab6 (patch) | |
tree | b3bb18facba243850b1c1094108d266769f251df /shell | |
parent | 5e34ff29bcc870936ab18172f438a34d042d4e03 (diff) | |
download | busybox-w32-950bd729665cecf1fbee65bc6e57e087c93aaab6.tar.gz busybox-w32-950bd729665cecf1fbee65bc6e57e087c93aaab6.tar.bz2 busybox-w32-950bd729665cecf1fbee65bc6e57e087c93aaab6.zip |
hush: speed up set_local_var
function old new delta
set_local_var 265 290 +25
Diffstat (limited to 'shell')
-rw-r--r-- | shell/hush.c | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/shell/hush.c b/shell/hush.c index 58a57d961..53b1f3f8b 100644 --- a/shell/hush.c +++ b/shell/hush.c | |||
@@ -1266,16 +1266,16 @@ static const char *get_local_var_value(const char *src) | |||
1266 | static int set_local_var(char *str, int flg_export, int flg_read_only) | 1266 | static int set_local_var(char *str, int flg_export, int flg_read_only) |
1267 | { | 1267 | { |
1268 | struct variable *cur; | 1268 | struct variable *cur; |
1269 | char *value; | 1269 | char *eq_sign; |
1270 | int name_len; | 1270 | int name_len; |
1271 | 1271 | ||
1272 | value = strchr(str, '='); | 1272 | eq_sign = strchr(str, '='); |
1273 | if (!value) { /* not expected to ever happen? */ | 1273 | if (!eq_sign) { /* not expected to ever happen? */ |
1274 | free(str); | 1274 | free(str); |
1275 | return -1; | 1275 | return -1; |
1276 | } | 1276 | } |
1277 | 1277 | ||
1278 | name_len = value - str + 1; /* including '=' */ | 1278 | name_len = eq_sign - str + 1; /* including '=' */ |
1279 | cur = G.top_var; /* cannot be NULL (we have HUSH_VERSION and it's RO) */ | 1279 | cur = G.top_var; /* cannot be NULL (we have HUSH_VERSION and it's RO) */ |
1280 | while (1) { | 1280 | while (1) { |
1281 | if (strncmp(cur->varstr, str, name_len) != 0) { | 1281 | 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) | |||
1288 | continue; | 1288 | continue; |
1289 | } | 1289 | } |
1290 | /* We found an existing var with this name */ | 1290 | /* We found an existing var with this name */ |
1291 | *value = '\0'; | ||
1292 | if (cur->flg_read_only) { | 1291 | if (cur->flg_read_only) { |
1293 | #if !BB_MMU | 1292 | #if !BB_MMU |
1294 | if (!flg_read_only) | 1293 | if (!flg_read_only) |
@@ -1297,11 +1296,13 @@ static int set_local_var(char *str, int flg_export, int flg_read_only) | |||
1297 | free(str); | 1296 | free(str); |
1298 | return -1; | 1297 | return -1; |
1299 | } | 1298 | } |
1300 | //TODO: optimize out redundant unsetenv/putenv's? | 1299 | if (flg_export == -1) { |
1301 | debug_printf_env("%s: unsetenv '%s'\n", __func__, str); | 1300 | debug_printf_env("%s: unsetenv '%s'\n", __func__, str); |
1302 | unsetenv(str); /* just in case */ | 1301 | *eq_sign = '\0'; |
1303 | *value = '='; | 1302 | unsetenv(str); |
1304 | if (strcmp(cur->varstr, str) == 0) { | 1303 | *eq_sign = '='; |
1304 | } | ||
1305 | if (strcmp(cur->varstr + name_len, eq_sign + 1) == 0) { | ||
1305 | free_and_exp: | 1306 | free_and_exp: |
1306 | free(str); | 1307 | free(str); |
1307 | goto exp; | 1308 | goto exp; |