Optimize parseNinjaString
The closures in parseNinjaString seem to confuse go's escape analysis, causing it to allocate a new stateFunc object on the heap for every character in the string. Convert the state functions to normal functions, and pass a pointer to a state object to provide access to the variables that were in the closure. The range iteration on the input string was iterating over UTF-8 runes, when all of the rune comparisons for state changes only look at ASCII bytes. Switch to iterating over bytes, stringState will pass through multi-byte characters in strings untouched. Together this reduces the time spent in parseNinjaString by >50%, and the overall execution time by >20%. Change-Id: I4c926b52b883d51e2f12a1673d03fcc2cfe83445
Loading
Please sign in to comment