Optimize Mongo::Connection#read_documents by using raw string operations and unpack() instead of the slower ByteBuffer.

This commit is contained in:
Hongli Lai (Phusion) 2010-09-11 19:46:10 +02:00 committed by Kyle Banker
parent 1c25541492
commit 2291a59fcc
1 changed files with 3 additions and 6 deletions

View File

@ -786,13 +786,10 @@ module Mongo
docs = []
number_remaining = number_received
while number_remaining > 0 do
buf = BSON::ByteBuffer.new
buf.put_array(receive_message_on_socket(4, sock).unpack("C*"))
buf.rewind
size = buf.get_int
buf.put_array(receive_message_on_socket(size - 4, sock).unpack("C*"), 4)
buf = receive_message_on_socket(4, sock)
size = buf.unpack('V')[0]
buf << receive_message_on_socket(size - 4, sock)
number_remaining -= 1
buf.rewind
docs << BSON::BSON_CODER.deserialize(buf)
end
[docs, number_received, cursor_id]