diff options
author | Eric Wong <e@80x24.org> | 2015-12-04 22:49:29 +0000 |
---|---|---|
committer | Eric Wong <e@80x24.org> | 2015-12-08 05:13:28 +0000 |
commit | b0cb2bb41e76c4c3bfedd87f49e5ff70e9b830e2 (patch) | |
tree | 9fe7e8181ea96596fea7e17914b4080d49810270 /lib/yahns/proxy_http_response.rb | |
parent | f6fc3ac41d8e43dfb8558be88ca4de9f6c856dd5 (diff) | |
download | yahns-opt-case.tar.gz |
Ruby-trunk (as of r52931) optimizes case dispatch for additional immediate values such as `nil', `true', and `false'. Rearrange our case statements (and take away some safety-checks :x) to take advantage of these optimizations in ruby-trunk. ref: https://bugs.ruby-lang.org/issues/11769 http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-core/71818 http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-core/71825
Diffstat (limited to 'lib/yahns/proxy_http_response.rb')
-rw-r--r-- | lib/yahns/proxy_http_response.rb | 50 |
1 files changed, 25 insertions, 25 deletions
diff --git a/lib/yahns/proxy_http_response.rb b/lib/yahns/proxy_http_response.rb index 3858456..13f8870 100644 --- a/lib/yahns/proxy_http_response.rb +++ b/lib/yahns/proxy_http_response.rb @@ -13,12 +13,12 @@ module Yahns::HttpResponse # :nodoc: # no write buffer, try to write directly to the client socket case rv = String === buf ? kgio_trywrite(buf) : kgio_trywritev(buf) when nil then return # done writing buf, likely - when String, Array # partial write, hope the skb grows - buf = rv when :wait_writable, :wait_readable wbuf = Yahns::Wbuf.new(nil, alive, self.class.output_buffer_tmpdir, rv) buf = buf.join if Array === buf break + else # String, Array # partial write, hope the skb grows + buf = rv end while true end @@ -97,12 +97,12 @@ module Yahns::HttpResponse # :nodoc: # send the headers case rv = kgio_syssend(res, flags) when nil then break # all done, likely - when String # partial write, highly unlikely - flags = MSG_DONTWAIT - res = rv # hope the skb grows when :wait_writable, :wait_readable # highly unlikely in real apps wbuf = proxy_write(nil, res, alive) break # keep buffering as much as possible + else # String # partial write, highly unlikely + flags = MSG_DONTWAIT + res = rv # hope the skb grows end while true rbuf = Thread.current[:yahns_rbuf] @@ -112,26 +112,26 @@ module Yahns::HttpResponse # :nodoc: if len = kcar.body_bytes_left case tmp = tip.shift || req_res.kgio_tryread(0x2000, rbuf) - when String - len = kcar.body_bytes_left -= tmp.size - wbuf = proxy_write(wbuf, tmp, alive) when nil # premature EOF return proxy_err_response(nil, req_res, nil, wbuf) when :wait_readable return wait_on_upstream(req_res, alive, wbuf) + else # String + len = kcar.body_bytes_left -= tmp.size + wbuf = proxy_write(wbuf, tmp, alive) end until len == 0 elsif kcar.chunked? # nasty chunked body req_res.proxy_trailers = nil # define to avoid warnings for now buf = '' case tmp = tip.shift || req_res.kgio_tryread(0x2000, rbuf) - when String - kcar.filter_body(buf, tmp) - wbuf = proxy_write(wbuf, chunk_out(buf), alive) unless buf.empty? when nil # premature EOF return proxy_err_response(nil, req_res, nil, wbuf) when :wait_readable return wait_on_upstream(req_res, alive, wbuf) + else # String + kcar.filter_body(buf, tmp) + wbuf = proxy_write(wbuf, chunk_out(buf), alive) unless buf.empty? end until kcar.body_eof? buf = tmp @@ -139,12 +139,12 @@ module Yahns::HttpResponse # :nodoc: rbuf = Thread.current[:yahns_rbuf] = '' until kcar.trailers(tlr, buf) case rv = req_res.kgio_tryread(0x2000, rbuf) - when String - buf << rv when :wait_readable return wait_on_upstream(req_res, alive, wbuf) when nil # premature EOF return proxy_err_response(nil, req_res, nil, wbuf) + else # String + buf << rv end # no loop here end wbuf = proxy_write(wbuf, trailer_out(tlr), alive) @@ -152,13 +152,13 @@ module Yahns::HttpResponse # :nodoc: else # no Content-Length or Transfer-Encoding: chunked, wait on EOF! case tmp = tip.shift || req_res.kgio_tryread(0x2000, rbuf) - when String - wbuf = proxy_write(wbuf, tmp, alive) when nil req_res.shutdown break when :wait_readable return wait_on_upstream(req_res, alive, wbuf) + else # String + wbuf = proxy_write(wbuf, tmp, alive) end while true end @@ -176,13 +176,13 @@ module Yahns::HttpResponse # :nodoc: if len = kcar.body_bytes_left case tmp = req_res.kgio_tryread(0x2000, rbuf) - when String - len = kcar.body_bytes_left -= tmp.size - wbuf.wbuf_write(self, tmp) when nil # premature EOF return proxy_err_response(nil, req_res, nil, wbuf) when :wait_readable return :wait_readable # self remains in :ignore, wait on upstream + else # String + len = kcar.body_bytes_left -= tmp.size + wbuf.wbuf_write(self, tmp) end while len != 0 elsif kcar.chunked? # nasty chunked body @@ -191,13 +191,13 @@ module Yahns::HttpResponse # :nodoc: unless req_res.proxy_trailers # are we done dechunking the main body, yet? case tmp = req_res.kgio_tryread(0x2000, rbuf) - when String - kcar.filter_body(buf, tmp) - buf.empty? or wbuf.wbuf_write(self, chunk_out(buf)) when nil # premature EOF return proxy_err_response(nil, req_res, nil, wbuf) when :wait_readable return :wait_readable # self remains in :ignore, wait on upstream + else # String + kcar.filter_body(buf, tmp) + buf.empty? or wbuf.wbuf_write(self, chunk_out(buf)) end until kcar.body_eof? req_res.proxy_trailers = [ tmp, [] ] # onto trailers! rbuf = Thread.current[:yahns_rbuf] = '' @@ -206,12 +206,12 @@ module Yahns::HttpResponse # :nodoc: buf, tlr = *req_res.proxy_trailers until kcar.trailers(tlr, buf) case rv = req_res.kgio_tryread(0x2000, rbuf) - when String - buf << rv when :wait_readable return :wait_readable when nil # premature EOF return proxy_err_response(nil, req_res, nil, wbuf) + else # String + buf << rv end # no loop here end wbuf.wbuf_write(self, trailer_out(tlr)) @@ -219,13 +219,13 @@ module Yahns::HttpResponse # :nodoc: else # no Content-Length or Transfer-Encoding: chunked, wait on EOF! case tmp = req_res.kgio_tryread(0x2000, rbuf) - when String - wbuf.wbuf_write(self, tmp) when nil req_res.shutdown break when :wait_readable return :wait_readable # self remains in :ignore, wait on upstream + else # String + wbuf.wbuf_write(self, tmp) end while true end |