From ed9f3e90939cfa9efcc6e5e9382f1e1f40c49834 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Fri, 18 Jun 2010 06:41:58 +0000 Subject: prefer Array#[] lookup to Array#first/Array#last Array#[] lookups are slightly faster under both rbx and 1.9, and easier to read. --- lib/rainbows/event_machine.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'lib/rainbows/event_machine.rb') diff --git a/lib/rainbows/event_machine.rb b/lib/rainbows/event_machine.rb index 12d9e5e..e5560d3 100644 --- a/lib/rainbows/event_machine.rb +++ b/lib/rainbows/event_machine.rb @@ -80,7 +80,7 @@ module Rainbows # too tricky to support pipelining with :async since the # second (pipelined) request could be a stuck behind a # long-running async response - (response.nil? || -1 == response.first) and return @state = :close + (response.nil? || -1 == response[0]) and return @state = :close alive = @hp.keepalive? && G.alive out = [ alive ? CONN_ALIVE : CONN_CLOSE ] if @hp.headers? @@ -99,7 +99,7 @@ module Rainbows end def response_write(response, out = [ CONN_CLOSE ], alive = false) - @body = body = response.last + @body = body = response[2] if body.respond_to?(:errback) && body.respond_to?(:callback) body.callback { quit } body.errback { quit } @@ -118,7 +118,7 @@ module Rainbows if st.file? headers.delete('Transfer-Encoding') headers['Content-Length'] ||= st.size.to_s - response = [ response.first, headers.to_hash, [] ] + response = [ response[0], headers.to_hash, [] ] HttpResponse.write(self, response, out) stream = stream_file_data(body.to_path) stream.callback { quit } unless alive @@ -130,7 +130,7 @@ module Rainbows else out[0] = CONN_CLOSE end - response = [ response.first, headers.to_hash, [] ] + response = [ response[0], headers.to_hash, [] ] HttpResponse.write(self, response, out) if do_chunk EM.watch(io, ResponseChunkPipe, self).notify_readable = true -- cgit v1.2.3-24-ge0c7