Permalink
Browse files

Merge pull request #32 from bcg/bcg_buffer_perf

Buffer Performance
  • Loading branch information...
2 parents 657c30a + 2b142bf commit fc3267511ddc107a00c2f871da059a90dbf3cb75 @bcg committed Sep 13, 2011
Showing with 9 additions and 6 deletions.
  1. +2 −2 lib/em-mongo/connection.rb
  2. +7 −4 lib/em-mongo/server_response.rb
View
4 lib/em-mongo/connection.rb
@@ -154,7 +154,7 @@ def peek_size(buffer)
def receive_data(data)
- @buffer.append!(BSON::ByteBuffer.new(data.unpack('C*')))
+ @buffer.append!(data)
@buffer.rewind
while message_received?(@buffer)
@@ -165,7 +165,7 @@ def receive_data(data)
if @buffer.more?
remaining_bytes= @buffer.size-@buffer.position
- @buffer = BSON::ByteBuffer.new(@buffer.get(remaining_bytes))
+ @buffer = BSON::ByteBuffer.new(@buffer.to_s[@buffer.position,remaining_bytes])
@buffer.rewind
else
@buffer.clear
View
11 lib/em-mongo/server_response.rb
@@ -21,12 +21,15 @@ def initialize(buffer, connection)
@number_returned = buffer.get_int
# Documents
- @docs = (1..number_returned).map do
+ pos = buffer.position
+ @docs = (1..@number_returned).map do
size= @connection.peek_size(buffer)
- buf = buffer.get(size)
- BSON::BSON_CODER.deserialize(buf)
+ doc = BSON::BSON_CODER.deserialize(buffer.to_s[pos,size])
+ pos += size
+ buffer.position = pos
+ doc
end
end
end
-end
+end

0 comments on commit fc32675

Please sign in to comment.