From 72e1451159206af1c335b23e0c1e5bf9ed84bc85 Mon Sep 17 00:00:00 2001 From: Go MAEDA Date: Wed, 27 Mar 2019 02:15:24 +0000 Subject: Use Regexp#match? to reduce allocations of MatchData object (#28940). MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Patch by Pavel Rosický. git-svn-id: http://svn.redmine.org/redmine/trunk@18011 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- lib/redmine/field_format.rb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'lib/redmine/field_format.rb') diff --git a/lib/redmine/field_format.rb b/lib/redmine/field_format.rb index e1aba49f5..3d8a976fc 100644 --- a/lib/redmine/field_format.rb +++ b/lib/redmine/field_format.rb @@ -251,7 +251,7 @@ module Redmine [text, url] end links = texts_and_urls.sort_by(&:first).map do |text, url| - css_class = (url =~ /^https?:\/\//) ? 'external' : nil + css_class = (/^https?:\/\//.match?(url)) ? 'external' : nil view.link_to_if uri_with_safe_scheme?(url), text, url, :class => css_class end links.join(', ').html_safe @@ -360,7 +360,7 @@ module Redmine def validate_single_value(custom_field, value, customized=nil) errs = super value = value.to_s - unless custom_field.regexp.blank? or value =~ Regexp.new(custom_field.regexp) + unless custom_field.regexp.blank? or Regexp.new(custom_field.regexp).match?(value) errs << ::I18n.t('activerecord.errors.messages.invalid') end if custom_field.min_length && value.length < custom_field.min_length @@ -442,12 +442,12 @@ module Redmine url = url_from_pattern(custom_field, value, customized) else url = value.to_s - unless url =~ %r{\A[a-z]+://}i + unless %r{\A[a-z]+://}i.match?(url) # no protocol found, use http by default url = "http://" + url end end - css_class = (url =~ /^https?:\/\//) ? 'external' : nil + css_class = (/^https?:\/\//.match?(url)) ? 'external' : nil view.link_to value.to_s.truncate(40), url, :class => css_class else value.to_s @@ -492,7 +492,7 @@ module Redmine def validate_single_value(custom_field, value, customized=nil) errs = super - errs << ::I18n.t('activerecord.errors.messages.not_a_number') unless value.to_s.strip =~ /^[+-]?\d+$/ + errs << ::I18n.t('activerecord.errors.messages.not_a_number') unless /^[+-]?\d+$/.match?(value.to_s.strip) errs end @@ -536,7 +536,7 @@ module Redmine end def validate_single_value(custom_field, value, customized=nil) - if value =~ /^\d{4}-\d{2}-\d{2}$/ && (value.to_date rescue false) + if /^\d{4}-\d{2}-\d{2}$/.match?(value) && (value.to_date rescue false) [] else [::I18n.t('activerecord.errors.messages.not_a_date')] -- cgit v1.2.3