rubinius/rubinius — pull request #2285 by leocassarani (2013-04-17 00:17:24+00:00)
Title: Optimize Splitter in the matching delimiter regexp case

Inspired by @MSNexploder's profiling on #985, I did some digging around the `Splitter` class to see if I could optimise its execution time.

The main change is that we now avoid calling `MatchData#captures` in a tight loop unless there are in fact any captures.

I've also made a few micro-optimisations, like using `Array#concat` instead of `Array#push` with a splat, and favouring `Array#at(-1)` over `Array#last` when we know the array is not empty.

I used the benchmark in `benchmark/core/string/bench_split.rb` to guide my changes. In particular, the relevant benchmark is "matching delimiter regexp", which I ran against MRI.

Before:

Comparing benchmark/core/string/bench_split.rb:matching delimiter regexp:
ruby: 138829 i/s
bin/rbx: 48619 i/s - 2.86x slower

After:

Comparing benchmark/core/string/bench_split.rb:matching delimiter regexp:
ruby: 139696 i/s
bin/rbx: 138014 i/s - 1.01x slower