From: Makoto Kuwata Date: 2008-03-14T16:29:37+09:00 Subject: [ruby-dev:34048] CGI::Cookie.new を高速化するバッチ 桑田といいます。 cgi.rb において、CGI::Cookie.new を (多少ですが) 高速化する パッチです。 具体的には、CGI::Cookie::parse() と CGI#initialize() において 無駄な Hash が生成されるのをさけています。 もしよろしければ、とりこむことをご検討ください。 lib/cgi.rb ------------------------------------------------------------ diff -r a23fc207b656 lib/cgi.rb --- a/lib/cgi.rb Fri Mar 14 15:33:22 2008 +0900 +++ b/lib/cgi.rb Fri Mar 14 15:57:36 2008 +0900 @@ -792,11 +792,16 @@ class CGI # # These keywords correspond to attributes of the cookie object. def initialize(name = "", *value) - options = if name.kind_of?(String) - { "name" => name, "value" => value } - else - name - end + if name.kind_of?(String) + @name = name + @value = value + %r|^(.*/)|.match(ENV["SCRIPT_NAME"]) + @path = ($1 or "") + @secure = false + return super(@value) + end + + options = name unless options.has_key?("name") raise ArgumentError, "`name' required" end @@ -880,7 +885,7 @@ class CGI if cookies.has_key?(name) values = cookies[name].value + values end - cookies[name] = Cookie::new({ "name" => name, "value" => values }) + cookies[name] = Cookie::new(name, *values) end cookies ------------------------------------------------------------ 以上です。 -- makoto kuwata