-<Project Sdk="Microsoft.NET.Sdk">
+<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<ProjectGuid>{BAC347A3-9841-44FC-B1E3-2344D1152C23}</ProjectGuid>
<AssemblyName>System.Private.Xml.Linq</AssemblyName>
<Reference Include="System.Threading" />
<Reference Include="System.Threading.Tasks" />
<Reference Include="System.Threading.Thread" />
+ <Reference Include="System.Memory" />
</ItemGroup>
</Project>
\ No newline at end of file
{
private XHashtableState _state; // SHARED STATE: Contains all XHashtable state, so it can be atomically swapped when resizes occur
- private const int StartingHash = (5381 << 16) + 5381; // Starting hash code value for string keys to be hashed
-
/// <summary>
/// Prototype of function which is called to extract a string key value from a hashed value.
/// Returns null if the hashed value is invalid (e.g. value has been released due to a WeakReference TValue being cleaned up).
/// </summary>
private static int ComputeHashCode(string key, int index, int count)
{
- int hashCode = StartingHash;
- int end = index + count;
Debug.Assert(key != null, "key should have been checked previously for null");
-
- // Hash the key
- for (int i = index; i < end; i++)
- unchecked
- {
- hashCode += (hashCode << 7) ^ key[i];
- }
-
- // Mix up hash code a bit more and clear the sign bit. This code was taken from NameTable.cs in System.Xml.
- hashCode -= hashCode >> 17;
- hashCode -= hashCode >> 11;
- hashCode -= hashCode >> 5;
- return hashCode & 0x7FFFFFFF;
+ return string.GetHashCode(key.AsSpan(index, count));
}
/// <summary>
int hashCode = 0;
if (name != null)
{
- unchecked
- {
- for (int i = name.Length - 1; i >= 0; i--)
- {
- char ch = name[i];
- if (ch == ':') break;
- hashCode += (hashCode << 7) ^ ch;
- }
- hashCode -= hashCode >> 17;
- hashCode -= hashCode >> 11;
- hashCode -= hashCode >> 5;
- }
+ return string.GetHashCode(name.AsSpan(name.LastIndexOf(':') + 1));
}
return hashCode;
}