ruby-changes:59571
From: Oleg <ko1@a...>
Date: Tue, 31 Dec 2019 21:09:22 +0900 (JST)
Subject: [ruby-changes:59571] 4ce28b58cb (master): speed up set intersect
https://git.ruby-lang.org/ruby.git/commit/?id=4ce28b58cb From 4ce28b58cbf3f3b5ab0bcd3fa4479d4f6d427158 Mon Sep 17 00:00:00 2001 From: Oleg Zubchenko <RedGreenBlueDiamond@g...> Date: Sat, 3 Nov 2018 15:27:10 +0300 Subject: speed up set intersect diff --git a/lib/set.rb b/lib/set.rb index 5a96c81..e7d1be4 100644 --- a/lib/set.rb +++ b/lib/set.rb @@ -464,7 +464,15 @@ class Set https://github.com/ruby/ruby/blob/trunk/lib/set.rb#L464 # Set['a', 'b', 'z'] & ['a', 'b', 'c'] #=> #<Set: {"a", "b"}> def &(enum) n = self.class.new - do_with_enum(enum) { |o| n.add(o) if include?(o) } + if enum.is_a?(Set) + if enum.size > size + each { |o| n.add(o) if enum.include?(o) } + else + enum.each { |o| n.add(o) if include?(o) } + end + else + do_with_enum(enum) { |o| n.add(o) if include?(o) } + end n end alias intersection & -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/