From 645030ce070d32f6965a772956149fc8b6c99bce Mon Sep 17 00:00:00 2001 From: P. J. McDermott Date: Fri, 26 Feb 2016 21:12:13 -0500 Subject: eshtrans/frontend: Use printf in accept() instead of str concat This results in a very slight performance boost, trading memcpy()s for write()s. --- (limited to 'eshtrans') 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 } -- cgit v0.9.1