Browse Source

[SL.Core] Merge pull request SixLabors/Core#24 from carbon/master

Downgrade System.Buffers and Remove HashHelpers
af/octree-no-pixelmap
James Jackson-South 8 years ago
committed by GitHub
parent
commit
da547dbc2d
  1. 67
      src/SixLabors.Core/Helpers/HashHelpers.cs
  2. 2
      src/SixLabors.Core/SixLabors.Core.csproj
  3. 28
      tests/SixLabors.Core.Tests/Helpers/HashHelpersTests.cs

67
src/SixLabors.Core/Helpers/HashHelpers.cs

@ -1,67 +0,0 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using System;
namespace SixLabors
{
/// <summary>
/// Provides a set of helpers for combining object hashes.
/// </summary>
internal static class HashHelpers
{
/// <summary>
/// Combines the two specified hash codes.
/// </summary>
/// <param name="h1">Hash code one</param>
/// <param name="h2">Hash code two</param>
/// <returns>Returns a hash code for the provided hash codes.</returns>
[Obsolete("Use HashCode.Combine instead")]
public static int Combine(int h1, int h2)
{
// Lifted from coreFX repo
unchecked
{
// RyuJIT optimizes this to use the ROL instruction
// Related GitHub pull request: dotnet/coreclr#1830
uint rol5 = ((uint)h1 << 5) | ((uint)h1 >> 27);
return ((int)rol5 + h1) ^ h2;
}
}
/// <summary>
/// Combines the three specified hash codes.
/// </summary>
/// <param name="h1">The first </param>
/// <param name="h2">Hash code two</param>
/// <param name="h3">Hash code three</param>
/// <returns>Returns a hash code for the provided hash codes.</returns>
[Obsolete("Use HashCode.Combine instead")]
public static int Combine(int h1, int h2, int h3)
{
int hash = Combine(h1, h2);
hash = Combine(hash, h3);
return hash;
}
/// <summary>
/// Combines the four specified hash codes.
/// </summary>
/// <param name="h1">The first </param>
/// <param name="h2">Hash code two</param>
/// <param name="h3">Hash code three</param>
/// <param name="h4">Hash code four</param>
/// <returns>Returns a hash code for the provided hash codes.</returns>
[Obsolete("Use HashCode.Combine instead")]
public static int Combine(int h1, int h2, int h3, int h4)
{
int hash = Combine(h1, h2);
hash = Combine(hash, h3);
return Combine(hash, h4);
}
}
}

2
src/SixLabors.Core/SixLabors.Core.csproj

@ -48,7 +48,7 @@
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' != 'netcoreapp2.1' ">
<PackageReference Include="System.Buffers" Version="4.5.0" />
<PackageReference Include="System.Buffers" Version="4.4.0" />
<PackageReference Include="System.Memory" Version="4.5.1" />
</ItemGroup>

28
tests/SixLabors.Core.Tests/Helpers/HashHelpersTests.cs

@ -1,28 +0,0 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using Xunit;
namespace SixLabors.Tests.Helpers
{
public class HashHelpersTests
{
[Fact]
public void CanCombineTwoValues()
{
Assert.Equal(35, HashHelpers.Combine(1, 2));
}
[Fact]
public void CanCombineThreeValues()
{
Assert.Equal(1152, HashHelpers.Combine(1, 2, 3));
}
[Fact]
public void CanCombineFourValues()
{
Assert.Equal(38020, HashHelpers.Combine(1, 2, 3, 4));
}
}
}
Loading…
Cancel
Save