diff options
author | P. J. McDermott <pj@pehjota.net> | 2016-02-26 21:12:13 (EST) |
---|---|---|
committer | P. J. McDermott <pj@pehjota.net> | 2016-02-26 22:14:44 (EST) |
commit | 645030ce070d32f6965a772956149fc8b6c99bce (patch) | |
tree | 862b29a54f18839c68a76815d09c679f60d029f8 /eshtrans/frontend | |
parent | 1d7e6404126f95fbc6bd42336a576806f57ba930 (diff) | |
download | eggshell-645030ce070d32f6965a772956149fc8b6c99bce.zip eggshell-645030ce070d32f6965a772956149fc8b6c99bce.tar.gz eggshell-645030ce070d32f6965a772956149fc8b6c99bce.tar.bz2 |
eshtrans/frontend: Use printf in accept() instead of str concat
This results in a very slight performance boost, trading memcpy()s for
write()s.
Diffstat (limited to 'eshtrans/frontend')
-rw-r--r-- | eshtrans/frontend/lexer.esh | 20 |
1 files changed, 7 insertions, 13 deletions
diff --git a/eshtrans/frontend/lexer.esh b/eshtrans/frontend/lexer.esh index 224cef0..0c13836 100644 --- a/eshtrans/frontend/lexer.esh +++ b/eshtrans/frontend/lexer.esh @@ -30,7 +30,6 @@ here_queue= here_awaiting_end= here_awaiting_word= tok= -tokens= #dbg() #{ @@ -580,10 +579,10 @@ scan_wordexp() "${c}")"; then exit 1 fi - ln_off=${res%%${RS}*} - res="${res#*${RS}}" - c="${res%%${RS}*}" - res="${res#*${RS}}" + c="${res##*${RS}}" + res="${res%${RS}*}" + ln_off=${res##*${RS}} + res="${res%${RS}*}" ln_off=$((${ln_off} - ${lineno})) lineno=$((${lineno} + ${ln_off})) wordexp="\$(${SOH}C${STX}${res}" @@ -848,7 +847,6 @@ run_sublexer() here_queue='' here_awaiting_end=false here_awaiting_word=false - tokens='' c="${ch}" next @@ -864,7 +862,7 @@ run_sublexer() ;; esac - printf "%d${RS}%c${RS}%s" ${lineno} "${c}" "${tokens}" + printf "${RS}%d${RS}%c" ${lineno} "${c}" return 0 } @@ -885,7 +883,6 @@ run_lexer() here_queue='' here_awaiting_end=false here_awaiting_word=false - tokens='' # Read the first character and recognize the first token. lgetc @@ -899,9 +896,6 @@ run_lexer() synexp '' fi - # Return the tokens. - printf '%s' "${tokens}" - return 0 } @@ -1019,7 +1013,7 @@ accept() esac #dbg "accept $t" - tokens="${tokens}${tok}${RS}" + printf '%s' "${tok}${RS}" next return 0 } @@ -1041,6 +1035,6 @@ inject() local t="${1}" shift 1 - tokens="${tokens}${t}${RS}" + printf '%s' "${t}${RS}" return 0 } |