Permalink
Browse files

performance boost for String#blank? in Ruby 2.4

Some casual benchmarks showed a 2x factor.

All credit goes to @nurse.
  • Loading branch information...
fxn committed Jul 21, 2016
1 parent 575dbee commit 929a6500806fe671d9ac0002da8537bf26b8f25d
Showing with 1 addition and 1 deletion.
  1. +1 −1 activesupport/lib/active_support/core_ext/object/blank.rb
@@ -115,7 +115,7 @@ def blank?
# The regexp that matches blank strings is expensive. For the case of empty
# strings we can speed up this method (~3.5x) with an empty? call. The
# penalty for the rest of strings is marginal.
empty? || BLANK_RE === self
empty? || BLANK_RE.match?(self)
end
end

8 comments on commit 929a650

@jeremy

This comment has been minimized.

Member

jeremy replied Jul 21, 2016

❤️

@rafaelfranca

This comment has been minimized.

Member

rafaelfranca replied Jul 21, 2016

Is #match? present in Ruby 2.2 and 2.3?

@rafaelfranca

This comment has been minimized.

Member

rafaelfranca replied Jul 21, 2016

ah, we just defined.

@fxn

This comment has been minimized.

Member

fxn replied Jul 21, 2016

Yep, defined in 575dbee for reference.

@bogdanvlviv

This comment has been minimized.

Contributor

bogdanvlviv replied Jul 21, 2016

@fxn, can we change same as here?

(rails) $ ag "([A-Z]|/) === "

@rafaelfranca

This comment has been minimized.

Member

rafaelfranca replied Jul 21, 2016

@fxn

This comment has been minimized.

Member

fxn replied Jul 21, 2016

It has to be studied case by case, I need to do a pass.

@bogdanvlviv

This comment has been minimized.

Contributor

bogdanvlviv replied Jul 21, 2016

👍

Please sign in to comment.