Faster unsafe pointers
This commit is contained in:
parent
9edd6f60b9
commit
8fdfef460a
File diff suppressed because it is too large
Load Diff
|
|
@ -133,9 +133,9 @@ namespace Microsoft.AspNet.Server.Kestrel.Infrastructure
|
|||
}
|
||||
else if (_block.End - _index >= sizeof(long))
|
||||
{
|
||||
fixed (byte* ptr = _block.Array)
|
||||
fixed (byte* ptr = &_block.Array[_index])
|
||||
{
|
||||
return *(long*)(ptr + _index);
|
||||
return *(long*)(ptr);
|
||||
}
|
||||
}
|
||||
else if (_block.Next == null)
|
||||
|
|
@ -153,15 +153,15 @@ namespace Microsoft.AspNet.Server.Kestrel.Infrastructure
|
|||
}
|
||||
|
||||
long blockLong;
|
||||
fixed (byte* ptr = _block.Array)
|
||||
fixed (byte* ptr = &_block.Array[_block.End - sizeof(long)])
|
||||
{
|
||||
blockLong = *(long*)(ptr + _block.End - sizeof(long));
|
||||
blockLong = *(long*)(ptr);
|
||||
}
|
||||
|
||||
long nextLong;
|
||||
fixed (byte* ptr = _block.Next.Array)
|
||||
fixed (byte* ptr = &_block.Next.Array[_block.Next.Start])
|
||||
{
|
||||
nextLong = *(long*)(ptr + _block.Next.Start);
|
||||
nextLong = *(long*)(ptr );
|
||||
}
|
||||
|
||||
return (blockLong >> (sizeof(long) - blockBytes) * 8) | (nextLong << (sizeof(long) - nextBytes) * 8);
|
||||
|
|
@ -667,9 +667,10 @@ namespace Microsoft.AspNet.Server.Kestrel.Infrastructure
|
|||
bytesLeftInBlockMinusSpan = bytesLeftInBlock - 3;
|
||||
}
|
||||
|
||||
fixed (byte* pOutput = block.Data.Array)
|
||||
fixed (byte* pOutput = &block.Data.Array[block.End])
|
||||
{
|
||||
var output = pOutput + block.End;
|
||||
//this line is needed to allow output be an register var
|
||||
var output = pOutput;
|
||||
|
||||
var copied = 0;
|
||||
for (; input < inputEndMinusSpan && copied < bytesLeftInBlockMinusSpan; copied += 4)
|
||||
|
|
|
|||
|
|
@ -63,7 +63,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Infrastructure
|
|||
|
||||
var bytes = Encoding.ASCII.GetBytes(str);
|
||||
|
||||
fixed (byte* ptr = bytes)
|
||||
fixed (byte* ptr = &bytes[0])
|
||||
{
|
||||
return *(long*)ptr;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -239,7 +239,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
|
|||
}}
|
||||
protected override StringValues GetValueFast(string key)
|
||||
{{
|
||||
switch(key.Length)
|
||||
switch (key.Length)
|
||||
{{{Each(loop.HeadersByLength, byLength => $@"
|
||||
case {byLength.Key}:
|
||||
{{{Each(byLength, header => $@"
|
||||
|
|
@ -265,7 +265,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
|
|||
}}
|
||||
protected override bool TryGetValueFast(string key, out StringValues value)
|
||||
{{
|
||||
switch(key.Length)
|
||||
switch (key.Length)
|
||||
{{{Each(loop.HeadersByLength, byLength => $@"
|
||||
case {byLength.Key}:
|
||||
{{{Each(byLength, header => $@"
|
||||
|
|
@ -290,7 +290,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
|
|||
}}
|
||||
protected override void SetValueFast(string key, StringValues value)
|
||||
{{
|
||||
switch(key.Length)
|
||||
switch (key.Length)
|
||||
{{{Each(loop.HeadersByLength, byLength => $@"
|
||||
case {byLength.Key}:
|
||||
{{{Each(byLength, header => $@"
|
||||
|
|
@ -308,7 +308,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
|
|||
}}
|
||||
protected override void AddValueFast(string key, StringValues value)
|
||||
{{
|
||||
switch(key.Length)
|
||||
switch (key.Length)
|
||||
{{{Each(loop.HeadersByLength, byLength => $@"
|
||||
case {byLength.Key}:
|
||||
{{{Each(byLength, header => $@"
|
||||
|
|
@ -330,7 +330,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
|
|||
}}
|
||||
protected override bool RemoveFast(string key)
|
||||
{{
|
||||
switch(key.Length)
|
||||
switch (key.Length)
|
||||
{{{Each(loop.HeadersByLength, byLength => $@"
|
||||
case {byLength.Key}:
|
||||
{{{Each(byLength, header => $@"
|
||||
|
|
@ -388,42 +388,49 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
|
|||
if (_raw{header.Identifier} != null)
|
||||
{{
|
||||
output.CopyFrom(_raw{header.Identifier}, 0, _raw{header.Identifier}.Length);
|
||||
}} else ")}
|
||||
foreach(var value in _{header.Identifier})
|
||||
{{
|
||||
if (value != null)
|
||||
}}
|
||||
else ")}
|
||||
foreach (var value in _{header.Identifier})
|
||||
{{
|
||||
output.CopyFrom(_headerBytes, {header.BytesOffset}, {header.BytesCount});
|
||||
output.CopyFromAscii(value);
|
||||
if (value != null)
|
||||
{{
|
||||
output.CopyFrom(_headerBytes, {header.BytesOffset}, {header.BytesCount});
|
||||
output.CopyFromAscii(value);
|
||||
}}
|
||||
}}
|
||||
}}
|
||||
}}
|
||||
")}
|
||||
}}" : "")}
|
||||
public unsafe void Append(byte[] keyBytes, int keyOffset, int keyLength, string value)
|
||||
{{
|
||||
fixed(byte* ptr = keyBytes) {{ var pUB = ptr + keyOffset; var pUL = (ulong*)pUB; var pUI = (uint*)pUB; var pUS = (ushort*)pUB;
|
||||
switch(keyLength)
|
||||
{{{Each(loop.HeadersByLength, byLength => $@"
|
||||
case {byLength.Key}:
|
||||
{{{Each(byLength, header => $@"
|
||||
if ({header.EqualIgnoreCaseBytes()})
|
||||
{{
|
||||
if ({header.TestBit()})
|
||||
fixed (byte* ptr = &keyBytes[keyOffset])
|
||||
{{
|
||||
var pUB = ptr;
|
||||
var pUL = (ulong*)pUB;
|
||||
var pUI = (uint*)pUB;
|
||||
var pUS = (ushort*)pUB;
|
||||
switch (keyLength)
|
||||
{{{Each(loop.HeadersByLength, byLength => $@"
|
||||
case {byLength.Key}:
|
||||
{{{Each(byLength, header => $@"
|
||||
if ({header.EqualIgnoreCaseBytes()})
|
||||
{{
|
||||
_{header.Identifier} = AppendValue(_{header.Identifier}, value);
|
||||
if ({header.TestBit()})
|
||||
{{
|
||||
_{header.Identifier} = AppendValue(_{header.Identifier}, value);
|
||||
}}
|
||||
else
|
||||
{{
|
||||
{header.SetBit()};
|
||||
_{header.Identifier} = new StringValues(value);{(header.EnhancedSetter == false ? "" : $@"
|
||||
_raw{header.Identifier} = null;")}
|
||||
}}
|
||||
return;
|
||||
}}
|
||||
else
|
||||
{{
|
||||
{header.SetBit()};
|
||||
_{header.Identifier} = new StringValues(value);{(header.EnhancedSetter == false ? "" : $@"
|
||||
_raw{header.Identifier} = null;")}
|
||||
}}
|
||||
return;
|
||||
}}
|
||||
")}}}
|
||||
break;
|
||||
")}}}}}
|
||||
")}}}
|
||||
break;
|
||||
")}}}
|
||||
}}
|
||||
var key = System.Text.Encoding.ASCII.GetString(keyBytes, keyOffset, keyLength);
|
||||
StringValues existing;
|
||||
Unknown.TryGetValue(key, out existing);
|
||||
|
|
@ -462,8 +469,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
|
|||
}}
|
||||
}}
|
||||
}}
|
||||
")}}}
|
||||
";
|
||||
")}}}";
|
||||
}
|
||||
public virtual void AfterCompile(AfterCompileContext context)
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in New Issue