From bbb84a17213d60f25a61ae4a09111d5adac01a05 Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Fri, 29 Apr 2016 23:01:58 +0200 Subject: 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. --- activesupport/lib/active_support/core_ext/object/blank.rb | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'activesupport/lib/active_support/core_ext/object/blank.rb') 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 -- cgit v1.2.3