lotus/model — pull request #51 by splattael (2014-08-05 13:02:52+00:00)
Title: Avoid array allocations for generated coercer code

Before this commit the coercer generated following hashes:

Hash[*[:id, 1, :field, "string"]]

After this commit the coercer generates code with the same semantics:

Hash[:id, 1, :field, "string"]

This later code is not only shorter but also faster because it allocates
less array objects (no splat).

A small benchmark tries to proof it:

require 'benchmark/ips'

Benchmark.ips do |x|
x.report "hash simple" do
Hash[:foo, 1, :bar, 2]
end

x.report "hash splat" do
Hash[*[:foo, 1, :bar, 2]]
end
end

=begin

Calculating -------------------------------------
hash simple 91144 i/100ms
hash splat 80099 i/100ms
-------------------------------------------------
hash simple 2241513.4 (±1.3%) i/s - 11210712 in 5.002338s
hash splat 1840887.2 (±1.7%) i/s - 9211385 in 5.005211s
=end