Optimize Mongo::Connection#add_message_headers by packing data directly instead of using ByteBuffer.

This commit is contained in:
Hongli Lai (Phusion) 2010-09-13 22:53:16 +02:00 committed by Kyle Banker
parent f494c9601d
commit 87e6d578c1
1 changed files with 14 additions and 13 deletions

View File

@ -822,19 +822,20 @@ module Mongo
# Prepares a message for transmission to MongoDB by
# constructing a valid message header.
def add_message_headers(operation, message)
headers = BSON::ByteBuffer.new
headers = [
# Message size.
headers.put_int(16 + message.size)
16 + message.size,
# Unique request id.
headers.put_int(get_request_id)
get_request_id,
# Response id.
headers.put_int(0)
0,
# Opcode.
headers.put_int(operation)
operation
].pack('VVVV')
message.prepend!(headers)
end