Skip to content

Commit 199dc25

Browse files
bozarodomodwyer
authored andcommitted
Improve cursorData struct unmarshaling speed (#49)
This change remove full BSON decoding on: - parsing to `bson.Raw` and `bson.DocElem` fields; - skipping unused BSON fields.
1 parent 12fb1c2 commit 199dc25

File tree

3 files changed

+292
-197
lines changed

3 files changed

+292
-197
lines changed

bson/bson_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,19 @@ func testUnmarshal(c *C, data string, obj interface{}) {
8282
err := bson.Unmarshal([]byte(data), zero)
8383
c.Assert(err, IsNil)
8484
c.Assert(zero, DeepEquals, obj)
85+
86+
testUnmarshalRawElements(c, []byte(data))
87+
}
88+
89+
func testUnmarshalRawElements(c *C, data []byte) {
90+
elems := []bson.RawDocElem{}
91+
err := bson.Unmarshal(data, &elems)
92+
c.Assert(err, IsNil)
93+
for _, elem := range elems {
94+
if elem.Value.Kind == bson.ElementDocument || elem.Value.Kind == bson.ElementArray {
95+
testUnmarshalRawElements(c, elem.Value.Data)
96+
}
97+
}
8598
}
8699

87100
type testItemType struct {

0 commit comments

Comments
 (0)