Skip to content
Browse files

Added Rack::Request initialization memoization to reduce repetitive i…

…nstantiation cost.
  • Loading branch information...
1 parent 4f8d0fc commit eefbed89c4ece749e889132012d0f67cd87926a8 @mtodd mtodd committed Dec 24, 2008
Showing with 11 additions and 0 deletions.
  1. +11 −0 lib/rack/request.rb
View
11 lib/rack/request.rb
@@ -8,11 +8,22 @@ module Rack
# req = Rack::Request.new(env)
# req.post?
# req.params["data"]
+ #
+ # The environment hash passed will store a reference to the Request object
+ # instantiated so that it will only instantiate if an instance of the Request
+ # object doesn't already exist.
class Request
# The environment of the request.
attr_reader :env
+ def self.new(env)
+ unless env["rack.request"]
+ env["rack.request"] = super(env)
+ end
+ env["rack.request"]
+ end
+
def initialize(env)
@env = env
end

0 comments on commit eefbed8

Please sign in to comment.
Something went wrong with that request. Please try again.