Permalink
Browse files

restores the regexp used in String#blank?

This commit undoes 54243fe.

Reason: Further investigation has shown the benefit is not so clear
generally speaking.

There is a long discussion and several benchmarks in the PR #24658
if you are interested in the details.
  • Loading branch information...
fxn committed Apr 29, 2016
1 parent 517cf24 commit bbb84a17213d60f25a61ae4a09111d5adac01a05
Showing with 3 additions and 4 deletions.
  1. +3 −4 activesupport/lib/active_support/core_ext/object/blank.rb
@@ -97,6 +97,8 @@ class Hash
end
class String
BLANK_RE = /\A[[:space:]]*\z/
# A string is blank if it's empty or contains whitespaces only:
#
# ''.blank? # => true
@@ -113,10 +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.
#
# Double negation in the second operand is also a performance tweak, it is
# faster than the positive \A[[:space:]]*\z.
empty? || !(/[[:^space:]]/ === self)
empty? || BLANK_RE === self
end
end

0 comments on commit bbb84a1

Please sign in to comment.