diff options
author | Xavier Noria <fxn@hashref.com> | 2016-04-20 14:30:44 -0700 |
---|---|---|
committer | Xavier Noria <fxn@hashref.com> | 2016-04-20 14:30:44 -0700 |
commit | 115efeb036d4d56186ba7b0b64750cdc57471b59 (patch) | |
tree | 2b76c9077faf5aee01136d5011a0dd6995dbdbf2 /activesupport | |
parent | 3ff6b800f2fc3552d98a0a31947c66a21e4479eb (diff) | |
parent | 54243fecfc8867c79aa4adbfd9948ecd8dcbd8fc (diff) | |
download | rails-115efeb036d4d56186ba7b0b64750cdc57471b59.tar.gz rails-115efeb036d4d56186ba7b0b64750cdc57471b59.tar.bz2 rails-115efeb036d4d56186ba7b0b64750cdc57471b59.zip |
Merge pull request #24658 from schneems/schneems/faster-regex-blank-string
Speed up String#blank? Regex
Diffstat (limited to 'activesupport')
-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 |