Skip to content

Commit

Permalink
rename bufferPool > _bufferPool
Browse files Browse the repository at this point in the history
  • Loading branch information
pictos committed Jun 14, 2024
1 parent 3b3ab91 commit 39c2d87
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 33 deletions.
6 changes: 3 additions & 3 deletions LiteDB/Engine/Disk/DiskService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ internal class DiskService : IDisposable
private long _dataLength;
private long _logLength;

private static readonly ArrayPool<byte> bufferPool = ArrayPool<byte>.Shared;
private static readonly ArrayPool<byte> _bufferPool = ArrayPool<byte>.Shared;

public DiskService(
EngineSettings settings,
Expand Down Expand Up @@ -225,12 +225,12 @@ internal void MarkAsInvalidState()
{
using (var stream = _dataFactory.GetStream(true, true))
{
var buffer = bufferPool.Rent(PAGE_SIZE);
var buffer = _bufferPool.Rent(PAGE_SIZE);
stream.Read(buffer, 0, PAGE_SIZE);
buffer[HeaderPage.P_INVALID_DATAFILE_STATE] = 1;
stream.Position = 0;
stream.Write(buffer, 0, PAGE_SIZE);
bufferPool.Return(buffer);
_bufferPool.Return(buffer);
}
});
}
Expand Down
14 changes: 7 additions & 7 deletions LiteDB/Engine/Disk/Serializer/BufferReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ internal class BufferReader : IDisposable

private bool _isEOF = false;

private static readonly ArrayPool<byte> bufferPool = ArrayPool<byte>.Shared;
private static readonly ArrayPool<byte> _bufferPool = ArrayPool<byte>.Shared;

/// <summary>
/// Current global cursor position
Expand Down Expand Up @@ -163,13 +163,13 @@ public string ReadString(int count)
else
{
// rent a buffer to be re-usable
var buffer = bufferPool.Rent(count);
var buffer = _bufferPool.Rent(count);

this.Read(buffer, 0, count);

value = StringEncoding.UTF8.GetString(buffer, 0, count);

bufferPool.Return(buffer);
_bufferPool.Return(buffer);
}

return value;
Expand Down Expand Up @@ -253,13 +253,13 @@ private T ReadNumber<T>(Func<byte[], int, T> convert, int size)
}
else
{
var buffer = bufferPool.Rent(size);
var buffer = _bufferPool.Rent(size);

this.Read(buffer, 0, size);

value = convert(buffer, 0);

bufferPool.Return(buffer);
_bufferPool.Return(buffer);
}

return value;
Expand Down Expand Up @@ -330,13 +330,13 @@ public ObjectId ReadObjectId()
}
else
{
var buffer = bufferPool.Rent(12);
var buffer = _bufferPool.Rent(12);

this.Read(buffer, 0, 12);

value = new ObjectId(buffer, 0);

bufferPool.Return(buffer);
_bufferPool.Return(buffer);
}

return value;
Expand Down
18 changes: 9 additions & 9 deletions LiteDB/Engine/Disk/Serializer/BufferWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ internal class BufferWriter : IDisposable

private bool _isEOF = false;

private static readonly ArrayPool<byte> bufferPool = ArrayPool<byte>.Shared;
private static readonly ArrayPool<byte> _bufferPool = ArrayPool<byte>.Shared;

/// <summary>
/// Current global cursor position
Expand Down Expand Up @@ -169,7 +169,7 @@ public void WriteCString(string value)
}
else
{
var buffer = bufferPool.Rent(bytesCount);
var buffer = _bufferPool.Rent(bytesCount);

StringEncoding.UTF8.GetBytes(value, 0, value.Length, buffer, 0);

Expand All @@ -179,7 +179,7 @@ public void WriteCString(string value)

this.MoveForward(1);

bufferPool.Return(buffer);
_bufferPool.Return(buffer);
}
}

Expand All @@ -205,13 +205,13 @@ public void WriteString(string value, bool specs)
else
{
// rent a buffer to be re-usable
var buffer = bufferPool.Rent(count);
var buffer = _bufferPool.Rent(count);

StringEncoding.UTF8.GetBytes(value, 0, value.Length, buffer, 0);

this.Write(buffer, 0, count);

bufferPool.Return(buffer);
_bufferPool.Return(buffer);
}

if (specs)
Expand All @@ -234,13 +234,13 @@ private void WriteNumber<T>(T value, Action<T, byte[], int> toBytes, int size)
}
else
{
var buffer = bufferPool.Rent(size);
var buffer = _bufferPool.Rent(size);

toBytes(value, buffer, 0);

this.Write(buffer, 0, size);

bufferPool.Return(buffer);
_bufferPool.Return(buffer);
}
}

Expand Down Expand Up @@ -296,13 +296,13 @@ public void Write(ObjectId value)
}
else
{
var buffer = bufferPool.Rent(12);
var buffer = _bufferPool.Rent(12);

value.ToByteArray(buffer, 0);

this.Write(buffer, 0, 12);

bufferPool.Return(buffer);
_bufferPool.Return(buffer);
}
}

Expand Down
10 changes: 5 additions & 5 deletions LiteDB/Engine/Disk/Streams/AesStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class AesStream : Stream

private static readonly byte[] _emptyContent = new byte[PAGE_SIZE - 1 - 16]; // 1 for aes indicator + 16 for salt

private static readonly ArrayPool<byte> bufferPool = ArrayPool<byte>.Shared;
private static readonly ArrayPool<byte> _bufferPool = ArrayPool<byte>.Shared;

public byte[] Salt { get; }

Expand Down Expand Up @@ -55,8 +55,8 @@ public AesStream(string password, Stream stream)
// start stream from zero position
_stream.Position = 0;

var checkBuffer = bufferPool.Rent(32);
var msBuffer = bufferPool.Rent(16);
var checkBuffer = _bufferPool.Rent(32);
var msBuffer = _bufferPool.Rent(16);

try
{
Expand Down Expand Up @@ -159,8 +159,8 @@ public AesStream(string password, Stream stream)
}
finally
{
bufferPool.Return(msBuffer);
bufferPool.Return(checkBuffer);
_bufferPool.Return(msBuffer);
_bufferPool.Return(checkBuffer);
}
}

Expand Down
6 changes: 3 additions & 3 deletions LiteDB/Engine/Engine/Upgrade.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace LiteDB.Engine
public partial class LiteEngine
{

private static readonly ArrayPool<byte> bufferPool = ArrayPool<byte>.Shared;
private static readonly ArrayPool<byte> _bufferPool = ArrayPool<byte>.Shared;

/// <summary>
/// If Upgrade=true, run this before open Disk service
Expand All @@ -23,7 +23,7 @@ private void TryUpgrade()
// if file not exists, just exit
if (!File.Exists(filename)) return;

var buffer = bufferPool.Rent(1024);
var buffer = _bufferPool.Rent(1024);
using (var stream = new FileStream(
_settings.Filename,
FileMode.Open,
Expand All @@ -37,7 +37,7 @@ private void TryUpgrade()

if (FileReaderV7.IsVersion(buffer) == false) return;
}
bufferPool.Return(buffer);
_bufferPool.Return(buffer);
// run rebuild process
this.Recovery(_settings.Collation);
}
Expand Down
6 changes: 3 additions & 3 deletions LiteDB/Engine/Sort/SortContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ internal class SortContainer : IDisposable

private BufferReader _reader = null;

private static readonly ArrayPool<byte> bufferPool = ArrayPool<byte>.Shared;
private static readonly ArrayPool<byte> _bufferPool = ArrayPool<byte>.Shared;

/// <summary>
/// Returns if current container has no more items to read
Expand Down Expand Up @@ -122,7 +122,7 @@ public bool MoveNext()
/// </summary>
private IEnumerable<BufferSlice> GetSourceFromStream(Stream stream)
{
var bytes = bufferPool.Rent(PAGE_SIZE);
var bytes = _bufferPool.Rent(PAGE_SIZE);
var buffer = new BufferSlice(bytes, 0, PAGE_SIZE);

while (_readPosition < _size)
Expand All @@ -136,7 +136,7 @@ private IEnumerable<BufferSlice> GetSourceFromStream(Stream stream)
yield return buffer;
}

bufferPool.Return(bytes);
_bufferPool.Return(bytes);
}

public void Dispose()
Expand Down
6 changes: 3 additions & 3 deletions LiteDB/Engine/Sort/SortService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ internal class SortService : IDisposable
private readonly BufferSlice _buffer;
private readonly Lazy<Stream> _reader;

private static readonly ArrayPool<byte> bufferPool = ArrayPool<byte>.Shared;
private static readonly ArrayPool<byte> _bufferPool = ArrayPool<byte>.Shared;

/// <summary>
/// Get how many documents was inserted by Insert method
Expand All @@ -52,7 +52,7 @@ public SortService(SortDisk disk, int order, EnginePragmas pragmas)

_reader = new Lazy<Stream>(() => _disk.GetReader());

var bytes = bufferPool.Rent(disk.ContainerSize);
var bytes = _bufferPool.Rent(disk.ContainerSize);

_buffer = new BufferSlice(bytes, 0, _containerSize);
}
Expand All @@ -72,7 +72,7 @@ public void Dispose()
}

// return array buffer into pool
bufferPool.Return(_buffer.Array);
_bufferPool.Return(_buffer.Array);

// return open strem into disk
if (_reader.IsValueCreated)
Expand Down

0 comments on commit 39c2d87

Please sign in to comment.