Remove unnecessary fixed blocks
This commit is contained in:
parent
2aa10a64a2
commit
3a424f6aba
|
|
@ -18,6 +18,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public readonly IntPtr DataArrayPtr;
|
public readonly IntPtr DataArrayPtr;
|
||||||
|
|
||||||
|
internal unsafe readonly byte* DataFixedPtr;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The array segment describing the range of memory this block is tracking. The caller which has leased this block may only read and
|
/// The array segment describing the range of memory this block is tracking. The caller which has leased this block may only read and
|
||||||
/// modify the memory in this range.
|
/// modify the memory in this range.
|
||||||
|
|
@ -27,9 +29,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// This object cannot be instantiated outside of the static Create method
|
/// This object cannot be instantiated outside of the static Create method
|
||||||
/// </summary>
|
/// </summary>
|
||||||
protected MemoryPoolBlock(IntPtr dataArrayPtr)
|
unsafe protected MemoryPoolBlock(IntPtr dataArrayPtr)
|
||||||
{
|
{
|
||||||
DataArrayPtr = dataArrayPtr;
|
DataArrayPtr = dataArrayPtr;
|
||||||
|
DataFixedPtr = (byte*)dataArrayPtr.ToPointer();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
|
||||||
|
|
@ -175,10 +175,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure
|
||||||
}
|
}
|
||||||
else if (_block.End - _index >= sizeof(long))
|
else if (_block.End - _index >= sizeof(long))
|
||||||
{
|
{
|
||||||
fixed (byte* ptr = &_block.Array[_index])
|
return *(long*)(_block.DataFixedPtr + _index);
|
||||||
{
|
|
||||||
return *(long*)(ptr);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else if (_block.Next == null)
|
else if (_block.Next == null)
|
||||||
{
|
{
|
||||||
|
|
@ -194,17 +191,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
long blockLong;
|
var blockLong = *(long*)(_block.DataFixedPtr + _block.End - sizeof(long));
|
||||||
fixed (byte* ptr = &_block.Array[_block.End - sizeof(long)])
|
|
||||||
{
|
|
||||||
blockLong = *(long*)(ptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
long nextLong;
|
var nextLong = *(long*)(_block.Next.DataFixedPtr + _block.Next.Start);
|
||||||
fixed (byte* ptr = &_block.Next.Array[_block.Next.Start])
|
|
||||||
{
|
|
||||||
nextLong = *(long*)(ptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
return (blockLong >> (sizeof(long) - blockBytes) * 8) | (nextLong << (sizeof(long) - nextBytes) * 8);
|
return (blockLong >> (sizeof(long) - blockBytes) * 8) | (nextLong << (sizeof(long) - nextBytes) * 8);
|
||||||
}
|
}
|
||||||
|
|
@ -266,9 +255,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure
|
||||||
#if !DEBUG
|
#if !DEBUG
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
fixed (byte* ptr = &block.Array[index])
|
|
||||||
{
|
var pCurrent = (block.DataFixedPtr + index);
|
||||||
var pCurrent = ptr;
|
|
||||||
var pEnd = pCurrent + following;
|
var pEnd = pCurrent + following;
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
|
|
@ -281,7 +269,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure
|
||||||
pCurrent++;
|
pCurrent++;
|
||||||
index++;
|
index++;
|
||||||
} while (pCurrent < pEnd);
|
} while (pCurrent < pEnd);
|
||||||
}
|
|
||||||
|
|
||||||
following = 0;
|
following = 0;
|
||||||
break;
|
break;
|
||||||
|
|
@ -367,9 +354,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure
|
||||||
#if !DEBUG
|
#if !DEBUG
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
fixed (byte* ptr = &block.Array[index])
|
var pCurrent = (block.DataFixedPtr + index);
|
||||||
{
|
|
||||||
var pCurrent = ptr;
|
|
||||||
var pEnd = pCurrent + following;
|
var pEnd = pCurrent + following;
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
|
|
@ -388,7 +373,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure
|
||||||
pCurrent++;
|
pCurrent++;
|
||||||
index++;
|
index++;
|
||||||
} while (pCurrent != pEnd);
|
} while (pCurrent != pEnd);
|
||||||
}
|
|
||||||
|
|
||||||
following = 0;
|
following = 0;
|
||||||
break;
|
break;
|
||||||
|
|
@ -502,9 +486,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure
|
||||||
#if !DEBUG
|
#if !DEBUG
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
fixed (byte* ptr = &block.Array[index])
|
var pCurrent = (block.DataFixedPtr + index);
|
||||||
{
|
|
||||||
var pCurrent = ptr;
|
|
||||||
var pEnd = pCurrent + following;
|
var pEnd = pCurrent + following;
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
|
|
@ -529,7 +511,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure
|
||||||
pCurrent++;
|
pCurrent++;
|
||||||
index++;
|
index++;
|
||||||
} while (pCurrent != pEnd);
|
} while (pCurrent != pEnd);
|
||||||
}
|
|
||||||
|
|
||||||
following = 0;
|
following = 0;
|
||||||
break;
|
break;
|
||||||
|
|
@ -808,11 +789,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure
|
||||||
bytesLeftInBlockMinusSpan = bytesLeftInBlock - 3;
|
bytesLeftInBlockMinusSpan = bytesLeftInBlock - 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
fixed (byte* pOutput = &block.Data.Array[block.End])
|
var output = (block.DataFixedPtr + block.End);
|
||||||
{
|
|
||||||
//this line is needed to allow output be an register var
|
|
||||||
var output = pOutput;
|
|
||||||
|
|
||||||
var copied = 0;
|
var copied = 0;
|
||||||
for (; input < inputEndMinusSpan && copied < bytesLeftInBlockMinusSpan; copied += 4)
|
for (; input < inputEndMinusSpan && copied < bytesLeftInBlockMinusSpan; copied += 4)
|
||||||
{
|
{
|
||||||
|
|
@ -833,7 +810,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure
|
||||||
bytesLeftInBlock -= copied;
|
bytesLeftInBlock -= copied;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
block.End = blockIndex;
|
block.End = blockIndex;
|
||||||
_block = block;
|
_block = block;
|
||||||
|
|
|
||||||
|
|
@ -116,9 +116,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure
|
||||||
|
|
||||||
if (following > 0)
|
if (following > 0)
|
||||||
{
|
{
|
||||||
fixed (byte* blockStart = block.Array)
|
var input = block.DataFixedPtr + inputOffset;
|
||||||
{
|
|
||||||
var input = blockStart + inputOffset;
|
|
||||||
var i = 0;
|
var i = 0;
|
||||||
while (i < following - 11)
|
while (i < following - 11)
|
||||||
{
|
{
|
||||||
|
|
@ -170,7 +168,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure
|
||||||
|
|
||||||
remaining -= following;
|
remaining -= following;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (remaining == 0)
|
if (remaining == 0)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue