diff options
author | Eric Wong <e@80x24.org> | 2014-10-05 07:58:16 +0000 |
---|---|---|
committer | Eric Wong <e@80x24.org> | 2014-10-05 08:09:50 +0000 |
commit | 68e086d2b42ee2c9fc8017264aa353a0d543fd13 (patch) | |
tree | cd0d3f86173ae78ea1d2200d3a812d090b367b3f /lib/rack/server.rb | |
parent | 022b0076b0eacad03eac48060198f05aa776a866 (diff) | |
download | rack-master.tar.gz |
case/when dispatches already optimize away allocation of constant string literals in all C Ruby 1.9.x/2.x releases (ref: opt_case_dispatch in Ruby insns.def) Other Ruby implementations presumably have similar optimizations to encourage prettier code. The following code snippet does not cause GC.count to increase during the two loops, regardless of what `nr' is. Tested on Ruby 1.9.3, 2.1.3, and trunk r47786: GET = "GET" HEAD = "HEAD" REQUEST_METHOD = "REQUEST_METHOD" # unnecessary in 2.2.0+ env = { REQUEST_METHOD => "GET" } nr = 10000000 nr.times do |i| case env[REQUEST_METHOD] when GET, HEAD :foo else :bar end end a = GC.count nr.times do |i| case env[REQUEST_METHOD] when "GET", "HEAD" :foo else :bar end end b = GC.count p [ a, b ]
Diffstat (limited to 'lib/rack/server.rb')
0 files changed, 0 insertions, 0 deletions