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

ruby-changes:58192

From: Jean <ko1@a...>
Date: Thu, 10 Oct 2019 14:52:20 +0900 (JST)
Subject: [ruby-changes:58192] 717b72a8af (master): [rubygems/rubygems] Optimize Gem::Package::TarReader#each

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

From 717b72a8af6b99ca79fd5bbe52ba4bd16b038bf6 Mon Sep 17 00:00:00 2001
From: Jean Boussier <jean.boussier@g...>
Date: Tue, 1 Oct 2019 13:16:32 +0200
Subject: [rubygems/rubygems] Optimize Gem::Package::TarReader#each

https://github.com/rubygems/rubygems/commit/1de8f39ac4

diff --git a/lib/rubygems/package/tar_reader.rb b/lib/rubygems/package/tar_reader.rb
index f64915e..aa31ea2 100644
--- a/lib/rubygems/package/tar_reader.rb
+++ b/lib/rubygems/package/tar_reader.rb
@@ -55,6 +55,8 @@ class Gem::Package::TarReader https://github.com/ruby/ruby/blob/trunk/lib/rubygems/package/tar_reader.rb#L55
   def each
     return enum_for __method__ unless block_given?
 
+    use_seek = @io.respond_to?(:seek)
+
     until @io.eof? do
       header = Gem::Package::TarHeader.from @io
       return if header.empty?
@@ -67,18 +69,22 @@ class Gem::Package::TarReader https://github.com/ruby/ruby/blob/trunk/lib/rubygems/package/tar_reader.rb#L69
       skip = (512 - (size % 512)) % 512
       pending = size - entry.bytes_read
 
-      begin
-        # avoid reading...
-        @io.seek pending, IO::SEEK_CUR
-        pending = 0
-      rescue Errno::EINVAL, NameError
-        while pending > 0 do
-          bytes_read = @io.read([pending, 4096].min).size
-          raise UnexpectedEOF if @io.eof?
-          pending -= bytes_read
+      if use_seek
+        begin
+          # avoid reading if the @io supports seeking
+          @io.seek pending, IO::SEEK_CUR
+          pending = 0
+        rescue Errno::EINVAL
         end
       end
 
+      # if seeking isn't supported or failed
+      while pending > 0 do
+        bytes_read = @io.read([pending, 4096].min).size
+        raise UnexpectedEOF if @io.eof?
+        pending -= bytes_read
+      end
+
       @io.read skip # discard trailing zeros
 
       # make sure nobody can use #read, #getc or #rewind anymore
-- 
cgit v0.10.2


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

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