@@ -35,7 +35,7 @@ public sealed class SingleChunkBuffer : IByteBuffer
35
35
/// <param name="chunk">The chuns.</param>
36
36
/// <param name="length">The length.</param>
37
37
/// <param name="isReadOnly">Whether the buffer is read only.</param>
38
- internal SingleChunkBuffer ( IBsonChunk chunk , int length , bool isReadOnly = false )
38
+ public SingleChunkBuffer ( IBsonChunk chunk , int length , bool isReadOnly = false )
39
39
{
40
40
if ( chunk == null )
41
41
{
@@ -103,7 +103,8 @@ public ArraySegment<byte> AccessBackingBytes(int position)
103
103
throw new ArgumentOutOfRangeException ( "position" ) ;
104
104
}
105
105
106
- return new ArraySegment < byte > ( _chunk . Bytes . Array , _chunk . Bytes . Offset + position , _length - position ) ;
106
+ var segment = _chunk . Bytes ;
107
+ return new ArraySegment < byte > ( segment . Array , segment . Offset + position , _length - position ) ;
107
108
}
108
109
109
110
/// <inheritdoc/>
@@ -120,7 +121,8 @@ public void Clear(int position, int count)
120
121
}
121
122
EnsureIsWritable ( ) ;
122
123
123
- Array . Clear ( _chunk . Bytes . Array , _chunk . Bytes . Offset + position , count ) ;
124
+ var segment = _chunk . Bytes ;
125
+ Array . Clear ( segment . Array , segment . Offset + position , count ) ;
124
126
}
125
127
126
128
/// <inheritdoc/>
@@ -159,7 +161,8 @@ public byte GetByte(int position)
159
161
throw new ArgumentOutOfRangeException ( "position" ) ;
160
162
}
161
163
162
- return _chunk . Bytes . Array [ _chunk . Bytes . Offset + position ] ;
164
+ var segment = _chunk . Bytes ;
165
+ return segment . Array [ segment . Offset + position ] ;
163
166
}
164
167
165
168
/// <inheritdoc/>
@@ -183,7 +186,8 @@ public void GetBytes(int position, byte[] destination, int offset, int count)
183
186
throw new ArgumentOutOfRangeException ( "count" ) ;
184
187
}
185
188
186
- Buffer . BlockCopy ( _chunk . Bytes . Array , _chunk . Bytes . Offset + position , destination , offset , count ) ;
189
+ var segment = _chunk . Bytes ;
190
+ Buffer . BlockCopy ( segment . Array , segment . Offset + position , destination , offset , count ) ;
187
191
}
188
192
189
193
/// <inheritdoc/>
@@ -221,7 +225,8 @@ public void SetByte(int position, byte value)
221
225
}
222
226
EnsureIsWritable ( ) ;
223
227
224
- _chunk . Bytes . Array [ _chunk . Bytes . Offset + position ] = value ;
228
+ var segment = _chunk . Bytes ;
229
+ segment . Array [ segment . Offset + position ] = value ;
225
230
}
226
231
227
232
/// <inheritdoc/>
@@ -246,7 +251,8 @@ public void SetBytes(int position, byte[] source, int offset, int count)
246
251
}
247
252
EnsureIsWritable ( ) ;
248
253
249
- Buffer . BlockCopy ( source , offset , _chunk . Bytes . Array , _chunk . Bytes . Offset + position , count ) ;
254
+ var segment = _chunk . Bytes ;
255
+ Buffer . BlockCopy ( source , offset , segment . Array , segment . Offset + position , count ) ;
250
256
}
251
257
252
258
// private methods
0 commit comments