Skip to content

Commit

Permalink
RavenDB-23704 - use a const
Browse files Browse the repository at this point in the history
  • Loading branch information
grisha-kotler committed Mar 5, 2025
1 parent 3a6b940 commit 9a72254
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
5 changes: 3 additions & 2 deletions src/Sparrow.Server/ByteString.cs
Original file line number Diff line number Diff line change
Expand Up @@ -671,6 +671,7 @@ public sealed class ByteStringContext : ByteStringContext<ByteStringMemoryCache>
public const int MaxAllocationBlockSizeInBytes = 256 * MinBlockSizeInBytes;
public const int DefaultAllocationBlockSizeInBytes = 1 * MinBlockSizeInBytes;
public const int MinReusableBlockSizeInBytes = 8;
public const int MaxAllocatedBlockSize = 2 * Sparrow.Global.Constants.Size.Megabyte;

static unsafe ByteStringContext()
{
Expand Down Expand Up @@ -1040,7 +1041,7 @@ private ByteString AllocateExternal(byte* valuePtr, int size, ByteStringType typ
{
if (_externalCurrentLeft == 0)
{
var tmp = Math.Min(2 * Sparrow.Global.Constants.Size.Megabyte, AllocationBlockSize * 2);
var tmp = Math.Min(ByteStringContext.MaxAllocatedBlockSize, AllocationBlockSize * 2);
AllocateExternalSegment(tmp);
AllocationBlockSize = tmp;
}
Expand Down Expand Up @@ -1184,7 +1185,7 @@ private ByteString AllocateInternalUnlikely(int length, int allocationUnit, Byte
}
else
{
AllocationBlockSize = Math.Min(2 * Sparrow.Global.Constants.Size.Megabyte, AllocationBlockSize * 2);
AllocationBlockSize = Math.Min(ByteStringContext.MaxAllocatedBlockSize, AllocationBlockSize * 2);
var toAllocate = Math.Max(AllocationBlockSize, allocationUnit);
_internalCurrent = AllocateSegment(toAllocate);
Debug.Assert(_internalCurrent.SizeLeft >= allocationUnit, $"{_internalCurrent.SizeLeft} >= {allocationUnit}");
Expand Down
7 changes: 3 additions & 4 deletions test/FastTests/Sparrow/ByteStringTests.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Sparrow.Global;
using Sparrow.Server;
using Sparrow.Server;
using Sparrow.Threading;
using Tests.Infrastructure;
using Xunit;
Expand Down Expand Up @@ -200,12 +199,12 @@ public void CanReuseMemory()
{
using (var context = new ByteStringContext<ByteStringDirectAllocator>(SharedMultipleUseFlag.None))
{
while (context.AllocationBlockSize != 2 * Constants.Size.Megabyte)
while (context.AllocationBlockSize != ByteStringContext.MaxAllocatedBlockSize)
{
context.Allocate(ByteStringContext.MinBlockSizeInBytes / 2, out _);
}

Assert.Equal(2 * Constants.Size.Megabyte, context.AllocationBlockSize);
Assert.Equal(ByteStringContext.MaxAllocatedBlockSize, context.AllocationBlockSize);

const int toAllocate = ByteStringContext.MinBlockSizeInBytes * 5;
context.Allocate(toAllocate, out var first);
Expand Down

0 comments on commit 9a72254

Please sign in to comment.