Skip to content

Commit 0b315a5

Browse files
author
Robert Stam
committed
Merged pull request 101 with one minor change and some added comments.
1 parent c831935 commit 0b315a5

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

Bson/Serialization/BsonClassMapSerializer.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,17 +185,24 @@ public object Deserialize(
185185
}
186186
bsonReader.ReadEndDocument();
187187

188-
// check any members left over that we didn't have elements for
188+
// check any members left over that we didn't have elements for (in blocks of 32 elements at a time)
189189
for (var bitArrayIndex = 0; bitArrayIndex < memberMapBitArray.Length; ++bitArrayIndex)
190190
{
191191
var memberMapIndex = bitArrayIndex << 5;
192-
var memberMapBlock = ~memberMapBitArray[bitArrayIndex];
192+
var memberMapBlock = ~memberMapBitArray[bitArrayIndex]; // notice that bits are flipped so 1's are now the missing elements
193193

194+
// work through this memberMapBlock of 32 elements
194195
for (;;)
195196
{
197+
// examine missing elements (memberMapBlock is shifted right as we work through the block)
196198
while ((memberMapBlock & 1) != 0)
197199
{
198200
var memberMap = allMemberMaps[memberMapIndex];
201+
if (memberMap.IsReadOnly)
202+
{
203+
continue;
204+
}
205+
199206
if (memberMap.IsRequired)
200207
{
201208
var fieldOrProperty = (memberMap.MemberInfo.MemberType == MemberTypes.Field) ? "field" : "property";
@@ -215,6 +222,7 @@ public object Deserialize(
215222
break;
216223
}
217224

225+
// skip ahead to the next missing element
218226
var leastSignificantBit = FastMemberMapHelper.GetLeastSignificantBit(memberMapBlock);
219227
memberMapIndex += leastSignificantBit;
220228
memberMapBlock >>= leastSignificantBit;

0 commit comments

Comments
 (0)