aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support
diff options
context:
space:
mode:
Diffstat (limited to 'activesupport/lib/active_support')
-rw-r--r--activesupport/lib/active_support/core_ext/object/blank.rb7
1 files changed, 6 insertions, 1 deletions
diff --git a/activesupport/lib/active_support/core_ext/object/blank.rb b/activesupport/lib/active_support/core_ext/object/blank.rb
index 039c50a4a2..71d411b6d6 100644
--- a/activesupport/lib/active_support/core_ext/object/blank.rb
+++ b/activesupport/lib/active_support/core_ext/object/blank.rb
@@ -112,7 +112,12 @@ class String
#
# @return [true, false]
def blank?
- BLANK_RE === self
+ # 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
end
end