ractivejs/ractive — pull request #1229 by Rich-Harris (2014-09-18 14:36:49+00:00)
Title: Parser performance boost

This PR addresses #1227 - it changes the behaviour of `parser.getLinePos()`, but shouldn't affect anything externally.

Previously, `parser.getLinePos()` would return an object with various properties - `line`, `ch`, `text` etc - plus a `toJSON()` and `toString()` method. These were calculated for every single token, but mostly only used in the case of an error (`toJSON()` was also called if `parser.includeLinePositions` was `true`, in order to store line and column information).

Now, `parser.getLinePos( pos )` takes a character index and returns a `[lineNum, columnNum]` array. The only time the additional information is needed is if there's an error, so that logic has been moved into `parser.error()` instead.

Parsing is now a crazy amount faster (as in, an order of magnitude or two) - I reckon it's worth pushing a new version out so everyone can start benefitting straight away.