Move static BitCount method to base class

- Updated comment to point to a specific commit in corefx
- This is more consistent with AppendValue since BitCount doesn't need
  to be generated
This commit is contained in:
Stephen Halter 2015-10-09 17:27:33 -07:00
parent a33a5d0f1b
commit 3eec43a0c3
3 changed files with 16 additions and 48 deletions

View File

@ -586,22 +586,6 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
}
}
private static int BitCount(long value)
{
// see https://github.com/dotnet/corefx/blob/master/src/System.Reflection.Metadata/src/System/Reflection/Internal/Utilities/BitArithmetic.cs
const ulong Mask01010101 = 0x5555555555555555UL;
const ulong Mask00110011 = 0x3333333333333333UL;
const ulong Mask00001111 = 0x0F0F0F0F0F0F0F0FUL;
const ulong Mask00000001 = 0x0101010101010101UL;
var v = (ulong)value;
v = v - ((v >> 1) & Mask01010101);
v = (v & Mask00110011) + ((v >> 2) & Mask00110011);
return (int)(unchecked(((v + (v >> 4)) & Mask00001111) * Mask00000001) >> 56);
}
protected override int GetCountFast()
{
return BitCount(_bits) + (MaybeUnknown?.Count ?? 0);
@ -5428,22 +5412,6 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
}
}
private static int BitCount(long value)
{
// see https://github.com/dotnet/corefx/blob/master/src/System.Reflection.Metadata/src/System/Reflection/Internal/Utilities/BitArithmetic.cs
const ulong Mask01010101 = 0x5555555555555555UL;
const ulong Mask00110011 = 0x3333333333333333UL;
const ulong Mask00001111 = 0x0F0F0F0F0F0F0F0FUL;
const ulong Mask00000001 = 0x0101010101010101UL;
var v = (ulong)value;
v = v - ((v >> 1) & Mask01010101);
v = (v & Mask00110011) + ((v >> 2) & Mask00110011);
return (int)(unchecked(((v + (v >> 4)) & Mask00001111) * Mask00000001) >> 56);
}
protected override int GetCountFast()
{
return BitCount(_bits) + (MaybeUnknown?.Count ?? 0);

View File

@ -45,6 +45,22 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
return StringValues.Concat(existing, append);
}
protected static int BitCount(long value)
{
// see https://github.com/dotnet/corefx/blob/5965fd3756bc9dd9c89a27621eb10c6931126de2/src/System.Reflection.Metadata/src/System/Reflection/Internal/Utilities/BitArithmetic.cs
const ulong Mask01010101 = 0x5555555555555555UL;
const ulong Mask00110011 = 0x3333333333333333UL;
const ulong Mask00001111 = 0x0F0F0F0F0F0F0F0FUL;
const ulong Mask00000001 = 0x0101010101010101UL;
var v = (ulong)value;
v = v - ((v >> 1) & Mask01010101);
v = (v & Mask00110011) + ((v >> 2) & Mask00110011);
return (int)(unchecked(((v + (v >> 4)) & Mask00001111) * Mask00000001) >> 56);
}
protected virtual int GetCountFast()
{ throw new NotImplementedException(); }

View File

@ -192,22 +192,6 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
}}
}}
")}
private static int BitCount(long value)
{{
// see https://github.com/dotnet/corefx/blob/master/src/System.Reflection.Metadata/src/System/Reflection/Internal/Utilities/BitArithmetic.cs
const ulong Mask01010101 = 0x5555555555555555UL;
const ulong Mask00110011 = 0x3333333333333333UL;
const ulong Mask00001111 = 0x0F0F0F0F0F0F0F0FUL;
const ulong Mask00000001 = 0x0101010101010101UL;
var v = (ulong)value;
v = v - ((v >> 1) & Mask01010101);
v = (v & Mask00110011) + ((v >> 2) & Mask00110011);
return (int)(unchecked(((v + (v >> 4)) & Mask00001111) * Mask00000001) >> 56);
}}
protected override int GetCountFast()
{{
return BitCount(_bits) + (MaybeUnknown?.Count ?? 0);