Skip to content

Commit b04726c

Browse files
segiddinsdeivid-rodriguez
authored andcommitted
Use match? when regexp match data is unused
Improved performance / reduced allocations
1 parent 36c675c commit b04726c

File tree

11 files changed

+13
-13
lines changed

11 files changed

+13
-13
lines changed

bundler/lib/bundler/cli.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,8 @@ def help(cli = nil)
127127

128128
if man_pages.include?(command)
129129
man_page = man_pages[command]
130-
if Bundler.which("man") && man_path !~ %r{^file:/.+!/META-INF/jruby.home/.+}
131-
Kernel.exec "man #{man_page}"
130+
if Bundler.which("man") && !man_path.match?(%r{^file:/.+!/META-INF/jruby.home/.+})
131+
Kernel.exec("man", man_page)
132132
else
133133
puts File.read("#{man_path}/#{File.basename(man_page)}.ronn")
134134
end

bundler/lib/bundler/cli/common.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def self.select_spec(name, regex_match = nil)
5454

5555
Bundler.definition.specs.each do |spec|
5656
return spec if spec.name == name
57-
specs << spec if regexp && spec.name =~ regexp
57+
specs << spec if regexp && spec.name.match?(regexp)
5858
end
5959

6060
default_spec = default_gem_spec(name)

bundler/lib/bundler/shared_helpers.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ def set_path
334334
def set_rubyopt
335335
rubyopt = [ENV["RUBYOPT"]].compact
336336
setup_require = "-r#{File.expand_path("setup", __dir__)}"
337-
return if !rubyopt.empty? && rubyopt.first =~ /#{Regexp.escape(setup_require)}/
337+
return if !rubyopt.empty? && rubyopt.first.include?(setup_require)
338338
rubyopt.unshift setup_require
339339
Bundler::SharedHelpers.set_env "RUBYOPT", rubyopt.join(" ")
340340
end

bundler/lib/bundler/source/git/git_proxy.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ def current_branch
8787
def contains?(commit)
8888
allowed_with_path do
8989
result, status = git_null("branch", "--contains", commit, dir: path)
90-
status.success? && result =~ /^\* (.*)$/
90+
status.success? && result.match?(/^\* (.*)$/)
9191
end
9292
end
9393

bundler/lib/bundler/templates/Executable.bundler

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ m = Module.new do
2727
bundler_version = nil
2828
update_index = nil
2929
ARGV.each_with_index do |a, i|
30-
if update_index && update_index.succ == i && a =~ Gem::Version::ANCHORED_VERSION_PATTERN
30+
if update_index && update_index.succ == i && a.match?(Gem::Version::ANCHORED_VERSION_PATTERN)
3131
bundler_version = a
3232
end
3333
next unless a =~ /\A--bundler(?:[= ](#{Gem::Version::VERSION_PATTERN}))?\z/

bundler/lib/bundler/ui/shell.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ def tell_me(msg, color = nil, newline = nil)
130130
def tell_err(message, color = nil, newline = nil)
131131
return if @shell.send(:stderr).closed?
132132

133-
newline ||= message.to_s !~ /( |\t)\Z/
133+
newline ||= !message.to_s.match?(/( |\t)\Z/)
134134
message = word_wrap(message) if newline.is_a?(Hash) && newline[:wrap]
135135

136136
color = nil if color && !$stderr.tty?

lib/rubygems/command.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ def get_all_gem_names
190190
"Please specify at least one gem name (e.g. gem build GEMNAME)"
191191
end
192192

193-
args.select {|arg| arg !~ /^-/ }
193+
args.reject {|arg| arg.start_with?("-") }
194194
end
195195

196196
##

lib/rubygems/platform.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ def initialize(arch)
8989
when String then
9090
arch = arch.split "-"
9191

92-
if arch.length > 2 && arch.last !~ /\d+(\.\d+)?$/ # reassemble x86-linux-{libc}
92+
if arch.length > 2 && !arch.last.match?(/\d+(\.\d+)?$/) # reassemble x86-linux-{libc}
9393
extra = arch.pop
9494
arch.last << "-#{extra}"
9595
end
@@ -101,7 +101,7 @@ def initialize(arch)
101101
else cpu
102102
end
103103

104-
if arch.length == 2 && arch.last =~ /^\d+(\.\d+)?$/ # for command-line
104+
if arch.length == 2 && arch.last.match?(/^\d+(\.\d+)?$/) # for command-line
105105
@os, @version = arch
106106
return
107107
end

lib/rubygems/source/git.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ def uri_hash # :nodoc:
227227
require_relative "../openssl"
228228

229229
normalized =
230-
if @repository =~ %r{^\w+://(\w+@)?}
230+
if @repository.match?(%r{^\w+://(\w+@)?})
231231
uri = URI(@repository).normalize.to_s.sub %r{/$},""
232232
uri.sub(/\A(\w+)/) { $1.downcase }
233233
else

lib/rubygems/util.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ def self.glob_files_in_dir(glob, base_path)
109109
# comes with a leading slash.
110110

111111
def self.correct_for_windows_path(path)
112-
if path[0].chr == "/" && path[1].chr =~ /[a-z]/i && path[2].chr == ":"
112+
if path[0].chr == "/" && path[1].chr.match?(/[a-z]/i) && path[2].chr == ":"
113113
path[1..-1]
114114
else
115115
path

0 commit comments

Comments
 (0)