[前][次][番号順一覧][スレッド一覧]

ruby-changes:61540

From: Olle <ko1@a...>
Date: Fri, 5 Jun 2020 07:34:21 +0900 (JST)
Subject: [ruby-changes:61540] f61ee674d8 (master): [rubygems/rubygems] Prefer start_with? and end_with? over regex.

https://git.ruby-lang.org/ruby.git/commit/?id=f61ee674d8

From f61ee674d8c5871e8e81b1a7f5884635a0ee9803 Mon Sep 17 00:00:00 2001
From: Olle Jonsson <olle.jonsson@a...>
Date: Sun, 19 Apr 2020 18:06:02 +0200
Subject: [rubygems/rubygems] Prefer start_with? and end_with? over regex.

  - In one of the cases, filenames were checked for ending with "gz" -
    this is changed to check for ending with ".gz"
  - The change was made to make it even easier to read the code, and to
    match only from the start of the input (as opposed to start of the
    line)

https://github.com/rubygems/rubygems/commit/aac4290271

diff --git a/lib/rubygems/command.rb b/lib/rubygems/command.rb
index 2fb3dab..088f4ad 100644
--- a/lib/rubygems/command.rb
+++ b/lib/rubygems/command.rb
@@ -456,7 +456,9 @@ class Gem::Command https://github.com/ruby/ruby/blob/trunk/lib/rubygems/command.rb#L456
     until extra.empty? do
       ex = []
       ex << extra.shift
-      ex << extra.shift if extra.first.to_s =~ /^[^-]/
+      if (!extra.first.to_s.empty? && !extra.first.to_s.start_with?("-"))
+        ex << extra.shift
+      end
       result << ex if handles?(ex)
     end
 
diff --git a/lib/rubygems/remote_fetcher.rb b/lib/rubygems/remote_fetcher.rb
index e260926..da88ec4 100644
--- a/lib/rubygems/remote_fetcher.rb
+++ b/lib/rubygems/remote_fetcher.rb
@@ -252,7 +252,7 @@ class Gem::RemoteFetcher https://github.com/ruby/ruby/blob/trunk/lib/rubygems/remote_fetcher.rb#L252
 
     data = send "fetch_#{uri.scheme}", uri, mtime, head
 
-    if data and !head and uri.to_s =~ /\.gz$/
+    if data and !head and uri.to_s.end_with?(".gz")
       begin
         data = Gem::Util.gunzip data
       rescue Zlib::GzipFile::Error
diff --git a/lib/rubygems/specification.rb b/lib/rubygems/specification.rb
index ba90974..1d69807 100644
--- a/lib/rubygems/specification.rb
+++ b/lib/rubygems/specification.rb
@@ -2104,7 +2104,7 @@ class Gem::Specification < Gem::BasicSpecification https://github.com/ruby/ruby/blob/trunk/lib/rubygems/specification.rb#L2104
     end
 
     if @specification_version > CURRENT_SPECIFICATION_VERSION and
-      sym.to_s =~ /=$/
+        sym.to_s.end_with?("=")
       warn "ignoring #{sym} loading #{full_name}" if $DEBUG
     else
       super
diff --git a/lib/rubygems/test_utilities.rb b/lib/rubygems/test_utilities.rb
index 0edf3d6..0ad167b 100644
--- a/lib/rubygems/test_utilities.rb
+++ b/lib/rubygems/test_utilities.rb
@@ -49,7 +49,7 @@ class Gem::FakeFetcher https://github.com/ruby/ruby/blob/trunk/lib/rubygems/test_utilities.rb#L49
 
     path = path.to_s
     @paths << path
-    raise ArgumentError, 'need full URI' unless path =~ %r{^https?://}
+    raise ArgumentError, 'need full URI' unless path.start_with?("https://", "http://")
 
     unless @data.key? path
       raise Gem::RemoteFetcher::FetchError.new("no data for #{path}", path)
@@ -67,7 +67,7 @@ class Gem::FakeFetcher https://github.com/ruby/ruby/blob/trunk/lib/rubygems/test_utilities.rb#L67
     if data.respond_to?(:call)
       data.call
     else
-      if path.to_s =~ /gz$/ and not data.nil? and not data.empty?
+      if path.to_s.end_with?(".gz") and not data.nil? and not data.empty?
         data = Gem::Util.gunzip data
       end
       data
-- 
cgit v0.10.2


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]