Optimize Mongo::Connection#add_message_headers by packing data directly instead of using ByteBuffer.
This commit is contained in:
parent
f494c9601d
commit
87e6d578c1
|
@ -822,19 +822,20 @@ module Mongo
|
||||||
# Prepares a message for transmission to MongoDB by
|
# Prepares a message for transmission to MongoDB by
|
||||||
# constructing a valid message header.
|
# constructing a valid message header.
|
||||||
def add_message_headers(operation, message)
|
def add_message_headers(operation, message)
|
||||||
headers = BSON::ByteBuffer.new
|
headers = [
|
||||||
|
# Message size.
|
||||||
# Message size.
|
16 + message.size,
|
||||||
headers.put_int(16 + message.size)
|
|
||||||
|
# Unique request id.
|
||||||
# Unique request id.
|
get_request_id,
|
||||||
headers.put_int(get_request_id)
|
|
||||||
|
# Response id.
|
||||||
# Response id.
|
0,
|
||||||
headers.put_int(0)
|
|
||||||
|
# Opcode.
|
||||||
# Opcode.
|
operation
|
||||||
headers.put_int(operation)
|
].pack('VVVV')
|
||||||
|
|
||||||
message.prepend!(headers)
|
message.prepend!(headers)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue