Skip to content

Commit

Permalink
Improve cursorData struct unmarshaling speed (#49)
Browse files Browse the repository at this point in the history
This change remove full BSON decoding on:

 - parsing to `bson.Raw` and `bson.DocElem` fields;
 - skipping unused BSON fields.
  • Loading branch information
bozaro authored and domodwyer committed Oct 19, 2017
1 parent 12fb1c2 commit 199dc25
Show file tree
Hide file tree
Showing 3 changed files with 292 additions and 197 deletions.
13 changes: 13 additions & 0 deletions bson/bson_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,19 @@ func testUnmarshal(c *C, data string, obj interface{}) {
err := bson.Unmarshal([]byte(data), zero)
c.Assert(err, IsNil)
c.Assert(zero, DeepEquals, obj)

testUnmarshalRawElements(c, []byte(data))
}

func testUnmarshalRawElements(c *C, data []byte) {
elems := []bson.RawDocElem{}
err := bson.Unmarshal(data, &elems)
c.Assert(err, IsNil)
for _, elem := range elems {
if elem.Value.Kind == bson.ElementDocument || elem.Value.Kind == bson.ElementArray {
testUnmarshalRawElements(c, elem.Value.Data)
}
}
}

type testItemType struct {
Expand Down
Loading

0 comments on commit 199dc25

Please sign in to comment.