Thanks Eric! On Sun, Oct 5, 2014 at 1:15 AM, Eric Wong wrote: > 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 ] > --- > Eric Wong wrote: > > I don't disagree with this commit at this time > > OK, I disagree with one part :) > > I think the following allocations may be elided in future C Ruby, too: > a) foo == "lit" (and "lit" == foo) > b) str << "lit" > > If you prefer `git pull" for this: > > The following changes since commit > 022b0076b0eacad03eac48060198f05aa776a866: > > Merge pull request #739 from schneems/schneems/fix-respond_to > (2014-10-02 21:29:17 +0200) > > are available in the git repository at: > > git://bogomips.org/rack.git when-lit > > for you to fetch changes up to 68e086d2b42ee2c9fc8017264aa353a0d543fd13: > > conditionalget: avoid const lookup in case/when (2014-10-05 08:09:50 > +0000) > > ---------------------------------------------------------------- > Eric Wong (1): > conditionalget: avoid const lookup in case/when > > lib/rack/conditionalget.rb | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/lib/rack/conditionalget.rb b/lib/rack/conditionalget.rb > index 3d4c78a..441dd38 100644 > --- a/lib/rack/conditionalget.rb > +++ b/lib/rack/conditionalget.rb > @@ -21,7 +21,7 @@ module Rack > > def call(env) > case env[REQUEST_METHOD] > - when GET, HEAD > + when "GET", "HEAD" > status, headers, body = @app.call(env) > headers = Utils::HeaderHash.new(headers) > if status == 200 && fresh?(env, headers) > -- > EW > > -- > > --- > You received this message because you are subscribed to the Google Groups > "Rack Development" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to rack-devel+unsubscribe@googlegroups.com. > For more options, visit https://groups.google.com/d/optout. > -- --- You received this message because you are subscribed to the Google Groups "Rack Development" group. To unsubscribe from this group and stop receiving emails from it, send an email to rack-devel+unsubscribe@googlegroups.com. For more options, visit https://groups.google.com/d/optout.