ruby-changes:37487
From: normal <ko1@a...>
Date: Thu, 12 Feb 2015 04:04:40 +0900 (JST)
Subject: [ruby-changes:37487] normal:r49568 (trunk): set: speed up Set#include?
normal 2015-02-12 04:04:16 +0900 (Thu, 12 Feb 2015) New Revision: 49568 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=49568 Log: set: speed up Set#include? * lib/set.rb (initialize): internal hash defaults to false * lib/set.rb (include?): use Hash#[] for optimized dispatch. Patch by Ismael Abreu <ismaelga@g...> [ruby-core:67664] [Misc #10754] Modified files: trunk/ChangeLog trunk/lib/set.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 49567) +++ ChangeLog (revision 49568) @@ -1,3 +1,11 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Thu Feb 12 03:28:05 2015 Eric Wong <e@8...> + + * lib/set.rb (initialize): internal hash defaults to false + + * lib/set.rb (include?): use Hash#[] for optimized dispatch. + Patch by Ismael Abreu <ismaelga@g...> + [ruby-core:67664] [Misc #10754] + Wed Feb 11 11:09:52 2015 Nobuyoshi Nakada <nobu@r...> * ext/digest/digest_conf.rb (digest_conf): check for CommonDigest. Index: lib/set.rb =================================================================== --- lib/set.rb (revision 49567) +++ lib/set.rb (revision 49568) @@ -78,7 +78,7 @@ class Set https://github.com/ruby/ruby/blob/trunk/lib/set.rb#L78 # If a block is given, the elements of enum are preprocessed by the # given block. def initialize(enum = nil, &block) # :yields: o - @hash ||= Hash.new + @hash ||= Hash.new(false) enum.nil? and return @@ -209,7 +209,7 @@ class Set https://github.com/ruby/ruby/blob/trunk/lib/set.rb#L209 # Returns true if the set contains the given object. def include?(o) - @hash.include?(o) + @hash[o] end alias member? include? -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/