Performance optimizations

This PR _tries_ to reduce method calls and object allocations.

See https://gist.github.com/splattael/5404417 for some benchmarks.
@pxlpnk I had to work around rubocop here. I'd use a simple assignment within condition again.