normal d9beb7690f net/protocol: optimize large read case
There are several places where rbuf_consume is called with
@rbuf.size as its length arg; simplify that case by avoiding
the slow String#slice! operation in favor of a lightweight
replacement.

The following script exhibits reduced memory usage and
runtimes using the time(1) command:

	2.9s =>  2.6s
	70MB => 12 MB

---------
require 'net/http'
require 'digest/md5'
Thread.abort_on_exception = true
s = TCPServer.new('127.0.0.1', 0)
len = 1024 * 1024 * 1024
th = Thread.new do
  c = s.accept
  c.readpartial(16384)
  c.write("HTTP/1.0 200 OK\r\nContent-Length: #{len}\r\n\r\n")
  IO.copy_stream('/dev/zero', c, len)
  c.close
end

addr = s.addr
Net::HTTP.start(addr[3], addr[1]) do |http|
  http.request_get('/') do |res|
    dig = Digest::MD5.new
    res.read_body { |buf|
      dig.update(buf)
      # String#clear is important to reduce malloc overhead,
      # but most Ruby programmers don't do this :<
      buf.clear
    }
    puts dig.hexdigest
  end
end
----------

* lib/net/protocol (rbuf_consume): optimize for @rbuf.size == len
  [Feature #14268]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61602 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-05 02:22:23 +00:00
..
2017-12-30 12:10:43 +00:00
2017-10-22 11:27:06 +00:00
2017-12-31 00:06:34 +00:00
2017-10-08 07:00:01 +00:00
2017-12-25 05:54:27 +00:00
2017-10-08 07:00:01 +00:00
2017-12-14 06:30:22 +00:00
2017-12-24 08:38:43 +00:00
2017-09-12 08:38:06 +00:00
2017-12-22 08:00:10 +00:00
2017-12-22 08:00:10 +00:00
2017-10-21 13:34:19 +00:00
2017-12-25 07:55:25 +00:00
2017-10-08 07:00:01 +00:00
2017-10-08 07:00:01 +00:00
2017-12-23 23:33:09 +00:00
2017-12-20 04:25:01 +00:00
2017-12-22 23:08:05 +00:00
2017-10-21 12:34:13 +00:00
2017-11-22 21:13:51 +00:00
2017-10-08 07:00:01 +00:00
2017-10-08 07:00:01 +00:00