Optimize Mongo::Connection#send_message_on_socket: don't slice the input when not necessary.

This commit is contained in:
Hongli Lai (Phusion) 2010-09-13 22:55:36 +02:00 committed by Kyle Banker
parent 87e6d578c1
commit 6316c939d5
1 changed files with 8 additions and 5 deletions

View File

@ -845,11 +845,14 @@ module Mongo
# @return [Integer] number of bytes sent
def send_message_on_socket(packed_message, socket)
begin
total_bytes_sent = 0
while packed_message.size > 0
byte_sent = socket.send(packed_message, 0)
total_bytes_sent += byte_sent
packed_message.slice!(0, byte_sent)
total_bytes_sent = socket.send(packed_message, 0)
if total_bytes_sent != packed_message.size
packed_message.slice!(0, total_bytes_sent)
while packed_message.size > 0
byte_sent = socket.send(packed_message, 0)
total_bytes_sent += byte_sent
packed_message.slice!(0, byte_sent)
end
end
total_bytes_sent
rescue => ex