diff options
-rw-r--r-- | activesupport/lib/active_support/core_ext/object/blank.rb | 9 |
1 files changed, 3 insertions, 6 deletions
diff --git a/activesupport/lib/active_support/core_ext/object/blank.rb b/activesupport/lib/active_support/core_ext/object/blank.rb index 71d411b6d6..f7efa1e01a 100644 --- a/activesupport/lib/active_support/core_ext/object/blank.rb +++ b/activesupport/lib/active_support/core_ext/object/blank.rb @@ -112,12 +112,9 @@ class String # # @return [true, false] def blank? - # In practice, the majority of blank strings are empty. As of this writing - # checking for empty? is about 3.5x faster than matching against the regexp - # in MRI, so we call the predicate first, and then fallback. - # - # The penalty for blank strings with whitespace or present ones is marginal. - empty? || BLANK_RE === self + # Regex check is slow, only check non-empty strings. + # A string not blank if it contains a single non-space string. + empty? || !(/[[:^space:]]/ === self) end end |