aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2016-09-29 19:50:55 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2016-09-29 19:50:55 +0200
commit46e6498b2afccd093d03697313e0d0c2f6e4d38d (patch)
tree7527d9c60c2e58da81242bdaa185ff894f26a496
parent657086a3dc573649165a5271473fa1bcf58dc9ed (diff)
downloadbusybox-w32-46e6498b2afccd093d03697313e0d0c2f6e4d38d.tar.gz
busybox-w32-46e6498b2afccd093d03697313e0d0c2f6e4d38d.tar.bz2
busybox-w32-46e6498b2afccd093d03697313e0d0c2f6e4d38d.zip
hush: speed optimizations
Make o_addchr() faster: do not call o_grow_by() each time. Create i_getch_and_eat_bkslash_nl(), use it instead of peek+getch pair. function old new delta o_addchr 42 54 +12 parse_dollar 761 771 +10 o_grow_by 48 37 -11 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 3/1 up/down: 24/-11) Total: 11 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--shell/hush.c33
1 files changed, 27 insertions, 6 deletions
diff --git a/shell/hush.c b/shell/hush.c
index 177a794b5..65d7d870b 100644
--- a/shell/hush.c
+++ b/shell/hush.c
@@ -2373,7 +2373,7 @@ static ALWAYS_INLINE void o_free_unsafe(o_string *o)
2373static void o_grow_by(o_string *o, int len) 2373static void o_grow_by(o_string *o, int len)
2374{ 2374{
2375 if (o->length + len > o->maxlen) { 2375 if (o->length + len > o->maxlen) {
2376 o->maxlen += (2*len > B_CHUNK ? 2*len : B_CHUNK); 2376 o->maxlen += (2 * len) | (B_CHUNK-1);
2377 o->data = xrealloc(o->data, 1 + o->maxlen); 2377 o->data = xrealloc(o->data, 1 + o->maxlen);
2378 } 2378 }
2379} 2379}
@@ -2381,10 +2381,16 @@ static void o_grow_by(o_string *o, int len)
2381static void o_addchr(o_string *o, int ch) 2381static void o_addchr(o_string *o, int ch)
2382{ 2382{
2383 debug_printf("o_addchr: '%c' o->length=%d o=%p\n", ch, o->length, o); 2383 debug_printf("o_addchr: '%c' o->length=%d o=%p\n", ch, o->length, o);
2384 if (o->length < o->maxlen) {
2385 /* likely. avoid o_grow_by() call */
2386 add:
2387 o->data[o->length] = ch;
2388 o->length++;
2389 o->data[o->length] = '\0';
2390 return;
2391 }
2384 o_grow_by(o, 1); 2392 o_grow_by(o, 1);
2385 o->data[o->length] = ch; 2393 goto add;
2386 o->length++;
2387 o->data[o->length] = '\0';
2388} 2394}
2389 2395
2390#if 0 2396#if 0
@@ -3909,6 +3915,22 @@ static int parse_group(o_string *dest, struct parse_context *ctx,
3909 /* command remains "open", available for possible redirects */ 3915 /* command remains "open", available for possible redirects */
3910} 3916}
3911 3917
3918static int i_getch_and_eat_bkslash_nl(struct in_str *input)
3919{
3920 for (;;) {
3921 int ch, ch2;
3922
3923 ch = i_getch(input);
3924 if (ch != '\\')
3925 return ch;
3926 ch2 = i_peek(input);
3927 if (ch2 != '\n')
3928 return ch;
3929 /* backslash+newline, skip it */
3930 i_getch(input);
3931 }
3932}
3933
3912static int i_peek_and_eat_bkslash_nl(struct in_str *input) 3934static int i_peek_and_eat_bkslash_nl(struct in_str *input)
3913{ 3935{
3914 for (;;) { 3936 for (;;) {
@@ -4149,8 +4171,7 @@ static int parse_dollar(o_string *as_string,
4149 ch = i_getch(input); /* eat '{' */ 4171 ch = i_getch(input); /* eat '{' */
4150 nommu_addchr(as_string, ch); 4172 nommu_addchr(as_string, ch);
4151 4173
4152 i_peek_and_eat_bkslash_nl(input); 4174 ch = i_getch_and_eat_bkslash_nl(input); /* first char after '{' */
4153 ch = i_getch(input); /* first char after '{' */
4154 /* It should be ${?}, or ${#var}, 4175 /* It should be ${?}, or ${#var},
4155 * or even ${?+subst} - operator acting on a special variable, 4176 * or even ${?+subst} - operator acting on a special variable,
4156 * or the beginning of variable name. 4177 * or the beginning of variable name.