Skip to content

Commit

Permalink
Merge pull request #29 from casperisfine/save-alloc-proc
Browse files Browse the repository at this point in the history
Avoid the `block or return` pattern to save Proc allocations
  • Loading branch information
knu committed Jan 11, 2023
2 parents 02fcc7c + e89da97 commit cdff9ff
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/set.rb
Expand Up @@ -507,7 +507,7 @@ def disjoint?(set)
# the element as parameter. Returns an enumerator if no block is
# given.
def each(&block)
block or return enum_for(__method__) { size }
block_given? or return enum_for(__method__) { size }
@hash.each_key(&block)
self
end
Expand Down Expand Up @@ -582,7 +582,7 @@ def collect!
# Equivalent to Set#delete_if, but returns nil if no changes were
# made. Returns an enumerator if no block is given.
def reject!(&block)
block or return enum_for(__method__) { size }
block_given? or return enum_for(__method__) { size }
n = size
delete_if(&block)
self if size != n
Expand All @@ -591,7 +591,7 @@ def reject!(&block)
# Equivalent to Set#keep_if, but returns nil if no changes were
# made. Returns an enumerator if no block is given.
def select!(&block)
block or return enum_for(__method__) { size }
block_given? or return enum_for(__method__) { size }
n = size
keep_if(&block)
self if size != n
Expand Down

0 comments on commit cdff9ff

Please sign in to comment.