0
0
Fork 0

Optimize some regex matching (#15528)

* Use Regex#match?

* Replace =~ too

* Avoid to call match? from Nil

* Keep value of Regexp.last_match
This commit is contained in:
luigi 2021-01-22 04:09:08 -05:00 committed by GitHub
parent 7d0031a515
commit eb51e43fb4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 20 additions and 20 deletions

View file

@ -396,8 +396,8 @@ class FeedManager
active_filters.map! do |filter|
if filter.whole_word
sb = filter.phrase =~ /\A[[:word:]]/ ? '\b' : ''
eb = filter.phrase =~ /[[:word:]]\z/ ? '\b' : ''
sb = /\A[[:word:]]/.match?(filter.phrase) ? '\b' : ''
eb = /[[:word:]]\z/.match?(filter.phrase) ? '\b' : ''
/(?mix:#{sb}#{Regexp.escape(filter.phrase)}#{eb})/
else
@ -417,7 +417,7 @@ class FeedManager
status.media_attachments.map(&:description).join("\n\n"),
].compact.join("\n\n")
!combined_regex.match(combined_text).nil?
combined_regex.match?(combined_text)
end
# Adds a status to an account's feed, returning true if a status was