diff options
Diffstat (limited to 'activesupport/lib/active_support')
-rw-r--r-- | activesupport/lib/active_support/core_ext/object/blank.rb | 7 |
1 files changed, 3 insertions, 4 deletions
diff --git a/activesupport/lib/active_support/core_ext/object/blank.rb b/activesupport/lib/active_support/core_ext/object/blank.rb index 699b2fb42b..cb74bad73e 100644 --- a/activesupport/lib/active_support/core_ext/object/blank.rb +++ b/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 @@ class String # 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 |