Skip to content

Commit c18f0dc

Browse files
committed
- PR comments
1 parent 51ae949 commit c18f0dc

File tree

3 files changed

+35
-36
lines changed

3 files changed

+35
-36
lines changed

src/MongoDB.Bson/IO/BsonBinaryReader.cs

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
using System.Collections.Generic;
1818
using System.Globalization;
1919
using System.IO;
20-
using System.Linq;
2120

2221
namespace MongoDB.Bson.IO
2322
{
@@ -32,7 +31,7 @@ public class BsonBinaryReader : BsonReader
3231
#pragma warning restore CA2213 // Disposable never disposed
3332
private readonly BsonStream _bsonStream;
3433
private BsonBinaryReaderContext _context;
35-
private readonly Stack<BsonBinaryReaderContext> _contexts = new(4);
34+
private readonly Stack<BsonBinaryReaderContext> _contextStack = new(4);
3635

3736
// constructors
3837
/// <summary>
@@ -113,7 +112,7 @@ public override void Close()
113112
/// </summary>
114113
/// <returns>A bookmark.</returns>
115114
public override BsonReaderBookmark GetBookmark() =>
116-
new BsonBinaryReaderBookmark(State, CurrentBsonType, CurrentName, _context, _contexts, _bsonStream.Position);
115+
new BsonBinaryReaderBookmark(State, CurrentBsonType, CurrentName, _context, _contextStack, _bsonStream.Position);
117116

118117
/// <summary>
119118
/// Determines whether this reader is at end of file.
@@ -673,7 +672,7 @@ public override void ReturnToBookmark(BsonReaderBookmark bookmark)
673672
State = binaryReaderBookmark.State;
674673
CurrentBsonType = binaryReaderBookmark.CurrentBsonType;
675674
CurrentName = binaryReaderBookmark.CurrentName;
676-
_context = binaryReaderBookmark.RestoreContext(_contexts);
675+
_context = binaryReaderBookmark.RestoreContext(_contextStack);
677676
_bsonStream.Position = binaryReaderBookmark.Position;
678677
}
679678

@@ -782,7 +781,7 @@ private string GenerateDottedElementName()
782781
elementName = "?";
783782
}
784783

785-
return GenerateDottedElementName(_contexts.ToArray(), 0, elementName);
784+
return GenerateDottedElementName(_contextStack.ToArray(), 0, elementName);
786785
}
787786

788787
private string GenerateDottedElementName(BsonBinaryReaderContext[] contexts, int currentContextIndex, string elementName)
@@ -827,6 +826,23 @@ private BsonReaderState GetNextState()
827826
}
828827
}
829828

829+
private void PopContext()
830+
{
831+
var actualSize = _bsonStream.Position - _context.StartPosition;
832+
if (actualSize != _context.Size)
833+
{
834+
throw new FormatException($"Expected size to be {_context.Size}, not {actualSize}.");
835+
}
836+
837+
_context =_contextStack.Pop();
838+
}
839+
840+
private void PushContext(BsonBinaryReaderContext newContext)
841+
{
842+
_contextStack.Push(_context);
843+
_context = newContext;
844+
}
845+
830846
private int ReadSize()
831847
{
832848
int size = _bsonStream.ReadInt32();
@@ -842,22 +858,5 @@ private int ReadSize()
842858
}
843859
return size;
844860
}
845-
846-
private void PopContext()
847-
{
848-
var actualSize = _bsonStream.Position - _context.StartPosition;
849-
if (actualSize != _context.Size)
850-
{
851-
throw new FormatException($"Expected size to be {_context.Size}, not {actualSize}.");
852-
}
853-
854-
_context =_contexts.Pop();
855-
}
856-
857-
private void PushContext(BsonBinaryReaderContext newContext)
858-
{
859-
_contexts.Push(_context);
860-
_context = newContext;
861-
}
862861
}
863862
}

src/MongoDB.Bson/IO/BsonBinaryReaderBookmark.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@ internal BsonBinaryReaderBookmark(
3030
BsonType currentBsonType,
3131
string currentName,
3232
BsonBinaryReaderContext currentContext,
33-
Stack<BsonBinaryReaderContext> contextsStack,
33+
Stack<BsonBinaryReaderContext> contextStack,
3434
long position)
3535
: base(state, currentBsonType, currentName)
3636
{
3737
_context = currentContext;
38-
_contextArray = contextsStack.ToArray();
38+
_contextArray = contextStack.ToArray();
3939
_position = position;
4040
}
4141

src/MongoDB.Bson/IO/BsonBinaryWriter.cs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public class BsonBinaryWriter : BsonWriter
3030
#pragma warning restore CA2213 // Disposable never disposed
3131
private readonly BsonStream _bsonStream;
3232
private BsonBinaryWriterContext _context;
33-
private readonly Stack<BsonBinaryWriterContext> _contexts = new(4);
33+
private readonly Stack<BsonBinaryWriterContext> _contextStack = new(4);
3434

3535
// constructors
3636
/// <summary>
@@ -717,6 +717,17 @@ private BsonWriterState GetNextState()
717717
}
718718
}
719719

720+
private void PopContext()
721+
{
722+
_context = _contextStack.Pop();
723+
}
724+
725+
private void PushContext(BsonBinaryWriterContext newContext)
726+
{
727+
_contextStack.Push(_context);
728+
_context = newContext;
729+
}
730+
720731
private void WriteNameHelper()
721732
{
722733
if (_context.ContextType == ContextType.Array)
@@ -730,16 +741,5 @@ private void WriteNameHelper()
730741
_bsonStream.WriteCString(Name);
731742
}
732743
}
733-
734-
private void PopContext()
735-
{
736-
_context = _contexts.Pop();
737-
}
738-
739-
private void PushContext(BsonBinaryWriterContext newContext)
740-
{
741-
_contexts.Push(_context);
742-
_context = newContext;
743-
}
744744
}
745745
}

0 commit comments

Comments
 (0)