diff options
author | Xavier Noria <fxn@hashref.com> | 2016-04-29 23:01:58 +0200 |
---|---|---|
committer | Xavier Noria <fxn@hashref.com> | 2016-04-29 23:01:58 +0200 |
commit | bbb84a17213d60f25a61ae4a09111d5adac01a05 (patch) | |
tree | 46733f2b0f4b7976fb9656e370eb505cf2b7d738 /activesupport/lib/active_support | |
parent | 517cf249c369d4bca40b1f590ca641d8b717985e (diff) | |
download | rails-bbb84a17213d60f25a61ae4a09111d5adac01a05.tar.gz rails-bbb84a17213d60f25a61ae4a09111d5adac01a05.tar.bz2 rails-bbb84a17213d60f25a61ae4a09111d5adac01a05.zip |
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.
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 |