diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2018-07-31 10:36:29 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2018-07-31 10:36:29 +0200 |
commit | 54fdabda3b953087f669bfcba99b9ae3b0c09fec (patch) | |
tree | 04b891c27f69861cb263f39edb74f2ece63906b9 | |
parent | a5db1d7354977fe295882ff557e8f5fb23741b13 (diff) | |
download | busybox-w32-54fdabda3b953087f669bfcba99b9ae3b0c09fec.tar.gz busybox-w32-54fdabda3b953087f669bfcba99b9ae3b0c09fec.tar.bz2 busybox-w32-54fdabda3b953087f669bfcba99b9ae3b0c09fec.zip |
hush: speed up ${var:+ARG} for literal ARGs
function old new delta
first_special_char_in_vararg - 52 +52
expand_one_var 2248 2296 +48
encode_then_expand_vararg 357 336 -21
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 1/1 up/down: 100/-21) Total: 79 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | shell/hush.c | 58 |
1 files changed, 31 insertions, 27 deletions
diff --git a/shell/hush.c b/shell/hush.c index d17f7f29e..6852b5f79 100644 --- a/shell/hush.c +++ b/shell/hush.c | |||
@@ -5913,6 +5913,26 @@ static char *encode_then_expand_string(const char *str) | |||
5913 | return exp_str; | 5913 | return exp_str; |
5914 | } | 5914 | } |
5915 | 5915 | ||
5916 | static const char *first_special_char_in_vararg(const char *cp) | ||
5917 | { | ||
5918 | for (;;) { | ||
5919 | if (!*cp) return NULL; /* string has no special chars */ | ||
5920 | if (*cp == '$') return cp; | ||
5921 | if (*cp == '\\') return cp; | ||
5922 | if (*cp == '\'') return cp; | ||
5923 | if (*cp == '"') return cp; | ||
5924 | #if ENABLE_HUSH_TICK | ||
5925 | if (*cp == '`') return cp; | ||
5926 | #endif | ||
5927 | /* dquoted "${x:+ARG}" should not glob, therefore | ||
5928 | * '*' et al require some non-literal processing: */ | ||
5929 | if (*cp == '*') return cp; | ||
5930 | if (*cp == '?') return cp; | ||
5931 | if (*cp == '[') return cp; | ||
5932 | cp++; | ||
5933 | } | ||
5934 | } | ||
5935 | |||
5916 | /* Expanding ARG in ${var#ARG}, ${var%ARG}, or ${var/ARG/ARG}. | 5936 | /* Expanding ARG in ${var#ARG}, ${var%ARG}, or ${var/ARG/ARG}. |
5917 | * These can contain single- and double-quoted strings, | 5937 | * These can contain single- and double-quoted strings, |
5918 | * and treated as if the ARG string is initially unquoted. IOW: | 5938 | * and treated as if the ARG string is initially unquoted. IOW: |
@@ -5932,19 +5952,10 @@ static char *encode_then_expand_vararg(const char *str, int handle_squotes, int | |||
5932 | char *exp_str; | 5952 | char *exp_str; |
5933 | struct in_str input; | 5953 | struct in_str input; |
5934 | o_string dest = NULL_O_STRING; | 5954 | o_string dest = NULL_O_STRING; |
5935 | const char *cp; | ||
5936 | 5955 | ||
5937 | cp = str; | 5956 | if (!first_special_char_in_vararg(str)) { |
5938 | for (;;) { | 5957 | /* string has no special chars */ |
5939 | if (!*cp) return NULL; /* string has no special chars */ | 5958 | return NULL; |
5940 | if (*cp == '$') break; | ||
5941 | if (*cp == '\\') break; | ||
5942 | if (*cp == '\'') break; | ||
5943 | if (*cp == '"') break; | ||
5944 | #if ENABLE_HUSH_TICK | ||
5945 | if (*cp == '`') break; | ||
5946 | #endif | ||
5947 | cp++; | ||
5948 | } | 5959 | } |
5949 | 5960 | ||
5950 | setup_string_in_str(&input, str); | 5961 | setup_string_in_str(&input, str); |
@@ -6025,26 +6036,19 @@ static char *encode_then_expand_vararg(const char *str, int handle_squotes, int | |||
6025 | /* Expanding ARG in ${var+ARG}, ${var-ARG} | 6036 | /* Expanding ARG in ${var+ARG}, ${var-ARG} |
6026 | */ | 6037 | */ |
6027 | static int encode_then_append_var_plusminus(o_string *output, int n, | 6038 | static int encode_then_append_var_plusminus(o_string *output, int n, |
6028 | const char *str, int dquoted) | 6039 | char *str, int dquoted) |
6029 | { | 6040 | { |
6030 | struct in_str input; | 6041 | struct in_str input; |
6031 | o_string dest = NULL_O_STRING; | 6042 | o_string dest = NULL_O_STRING; |
6032 | 6043 | ||
6033 | #if 0 //todo? | 6044 | if (!first_special_char_in_vararg(str) |
6034 | const char *cp; | 6045 | && '\0' == str[strcspn(str, G.ifs)] |
6035 | cp = str; | 6046 | ) { |
6036 | for (;;) { | 6047 | /* string has no special chars |
6037 | if (!*cp) return NULL; /* string has no special chars */ | 6048 | * && string has no $IFS chars |
6038 | if (*cp == '$') break; | 6049 | */ |
6039 | if (*cp == '\\') break; | 6050 | return expand_vars_to_list(output, n, str); |
6040 | if (*cp == '\'') break; | ||
6041 | if (*cp == '"') break; | ||
6042 | #if ENABLE_HUSH_TICK | ||
6043 | if (*cp == '`') break; | ||
6044 | #endif | ||
6045 | cp++; | ||
6046 | } | 6051 | } |
6047 | #endif | ||
6048 | 6052 | ||
6049 | setup_string_in_str(&input, str); | 6053 | setup_string_in_str(&input, str); |
6050 | 6054 | ||