Skip to content
This repository was archived by the owner on Feb 22, 2020. It is now read-only.

Commit da3c590

Browse files
Merge pull request #23 from carbon/master
Add and use HashCode polyfill
2 parents 62634c0 + 4189346 commit da3c590

11 files changed

Lines changed: 472 additions & 30 deletions

File tree

src/SixLabors.Core/HashCode.cs

Lines changed: 447 additions & 0 deletions
Large diffs are not rendered by default.

src/SixLabors.Core/Helpers/HashHelpers.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// Copyright (c) Six Labors and contributors.
22
// Licensed under the Apache License, Version 2.0.
33

4+
using System;
5+
46
namespace SixLabors
57
{
68
/// <summary>
@@ -14,6 +16,7 @@ internal static class HashHelpers
1416
/// <param name="h1">Hash code one</param>
1517
/// <param name="h2">Hash code two</param>
1618
/// <returns>Returns a hash code for the provided hash codes.</returns>
19+
[Obsolete("Use HashCode.Combine instead")]
1720
public static int Combine(int h1, int h2)
1821
{
1922
// Lifted from coreFX repo
@@ -33,6 +36,7 @@ public static int Combine(int h1, int h2)
3336
/// <param name="h2">Hash code two</param>
3437
/// <param name="h3">Hash code three</param>
3538
/// <returns>Returns a hash code for the provided hash codes.</returns>
39+
[Obsolete("Use HashCode.Combine instead")]
3640
public static int Combine(int h1, int h2, int h3)
3741
{
3842
int hash = Combine(h1, h2);
@@ -50,6 +54,7 @@ public static int Combine(int h1, int h2, int h3)
5054
/// <param name="h3">Hash code three</param>
5155
/// <param name="h4">Hash code four</param>
5256
/// <returns>Returns a hash code for the provided hash codes.</returns>
57+
[Obsolete("Use HashCode.Combine instead")]
5358
public static int Combine(int h1, int h2, int h3, int h4)
5459
{
5560
int hash = Combine(h1, h2);

src/SixLabors.Core/Memory/ArrayPoolMemoryAllocator.CommonFactoryMethods.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ public static ArrayPoolMemoryAllocator CreateDefault()
4242
DefaultNormalPoolBucketCount);
4343
}
4444

45-
4645
/// <summary>
4746
/// For environments with very limited memory capabilities, only small buffers like image rows are pooled.
4847
/// </summary>
@@ -61,7 +60,6 @@ public static ArrayPoolMemoryAllocator CreateWithModeratePooling()
6160
return new ArrayPoolMemoryAllocator(1024 * 1024, 32 * 1024, 16, 24);
6261
}
6362

64-
6563
/// <summary>
6664
/// For environments where memory capabilities are not an issue, the maximum amount of array requests are pooled which results in optimal throughput.
6765
/// </summary>

src/SixLabors.Core/Primitives/Point.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public struct Point : IEquatable<Point>
2121
/// <summary>
2222
/// Represents a <see cref="Point"/> that has X and Y values set to zero.
2323
/// </summary>
24-
public static readonly Point Empty = default(Point);
24+
public static readonly Point Empty = default;
2525

2626
/// <summary>
2727
/// Initializes a new instance of the <see cref="Point"/> struct.
@@ -258,7 +258,7 @@ public void Offset(int dx, int dy)
258258
public void Offset(Point point) => this.Offset(point.X, point.Y);
259259

260260
/// <inheritdoc/>
261-
public override int GetHashCode() => HashHelpers.Combine(this.X.GetHashCode(), this.Y.GetHashCode());
261+
public override int GetHashCode() => HashCode.Combine(this.X, this.Y);
262262

263263
/// <inheritdoc/>
264264
public override string ToString() => $"Point [ X={this.X}, Y={this.Y} ]";

src/SixLabors.Core/Primitives/PointF.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public struct PointF : IEquatable<PointF>
2121
/// <summary>
2222
/// Represents a <see cref="PointF"/> that has X and Y values set to zero.
2323
/// </summary>
24-
public static readonly PointF Empty = default(PointF);
24+
public static readonly PointF Empty = default;
2525

2626
/// <summary>
2727
/// Initializes a new instance of the <see cref="PointF"/> struct.
@@ -267,10 +267,7 @@ public void Offset(float dx, float dy)
267267
public void Offset(PointF point) => this.Offset(point.X, point.Y);
268268

269269
/// <inheritdoc/>
270-
public override int GetHashCode()
271-
{
272-
return HashHelpers.Combine(this.X.GetHashCode(), this.Y.GetHashCode());
273-
}
270+
public override int GetHashCode() => HashCode.Combine(this.X, this.Y);
274271

275272
/// <inheritdoc/>
276273
public override string ToString() => $"PointF [ X={this.X}, Y={this.Y} ]";

src/SixLabors.Core/Primitives/Rectangle.cs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public struct Rectangle : IEquatable<Rectangle>
2020
/// <summary>
2121
/// Represents a <see cref="Rectangle"/> that has X, Y, Width, and Height values set to zero.
2222
/// </summary>
23-
public static readonly Rectangle Empty = default(Rectangle);
23+
public static readonly Rectangle Empty = default;
2424

2525
/// <summary>
2626
/// Initializes a new instance of the <see cref="Rectangle"/> struct.
@@ -425,11 +425,7 @@ public void Offset(int dx, int dy)
425425
/// <inheritdoc/>
426426
public override int GetHashCode()
427427
{
428-
return HashHelpers.Combine(
429-
this.X.GetHashCode(),
430-
this.Y.GetHashCode(),
431-
this.Width.GetHashCode(),
432-
this.Height.GetHashCode());
428+
return HashCode.Combine(this.X, this.Y, this.Width, this.Height);
433429
}
434430

435431
/// <inheritdoc/>

src/SixLabors.Core/Primitives/RectangleF.cs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public struct RectangleF : IEquatable<RectangleF>
2020
/// <summary>
2121
/// Represents a <see cref="RectangleF"/> that has X, Y, Width, and Height values set to zero.
2222
/// </summary>
23-
public static readonly RectangleF Empty = default(RectangleF);
23+
public static readonly RectangleF Empty = default;
2424

2525
/// <summary>
2626
/// Initializes a new instance of the <see cref="RectangleF"/> struct.
@@ -358,11 +358,7 @@ public void Offset(float dx, float dy)
358358
/// <inheritdoc/>
359359
public override int GetHashCode()
360360
{
361-
return HashHelpers.Combine(
362-
this.X.GetHashCode(),
363-
this.Y.GetHashCode(),
364-
this.Width.GetHashCode(),
365-
this.Height.GetHashCode());
361+
return HashCode.Combine(this.X, this.Y, this.Width, this.Height);
366362
}
367363

368364
/// <inheritdoc/>

src/SixLabors.Core/Primitives/Size.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public struct Size : IEquatable<Size>
2020
/// <summary>
2121
/// Represents a <see cref="Size"/> that has Width and Height values set to zero.
2222
/// </summary>
23-
public static readonly Size Empty = default(Size);
23+
public static readonly Size Empty = default;
2424

2525
/// <summary>
2626
/// Initializes a new instance of the <see cref="Size"/> struct.
@@ -252,7 +252,7 @@ public static SizeF Transform(Size size, Matrix3x2 matrix)
252252
public static Size Truncate(SizeF size) => new Size(unchecked((int)size.Width), unchecked((int)size.Height));
253253

254254
/// <inheritdoc/>
255-
public override int GetHashCode() => HashHelpers.Combine(this.Width.GetHashCode(), this.Height.GetHashCode());
255+
public override int GetHashCode() => HashCode.Combine(this.Width, this.Height);
256256

257257
/// <inheritdoc/>
258258
public override string ToString() => $"Size [ Width={this.Width}, Height={this.Height} ]";

src/SixLabors.Core/Primitives/SizeF.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public struct SizeF : IEquatable<SizeF>
2020
/// <summary>
2121
/// Represents a <see cref="SizeF"/> that has Width and Height values set to zero.
2222
/// </summary>
23-
public static readonly SizeF Empty = default(SizeF);
23+
public static readonly SizeF Empty = default;
2424

2525
/// <summary>
2626
/// Initializes a new instance of the <see cref="SizeF"/> struct.
@@ -198,10 +198,7 @@ public static SizeF Transform(SizeF size, Matrix3x2 matrix)
198198
}
199199

200200
/// <inheritdoc/>
201-
public override int GetHashCode()
202-
{
203-
return HashHelpers.Combine(this.Width.GetHashCode(), this.Height.GetHashCode());
204-
}
201+
public override int GetHashCode() => HashCode.Combine(this.Width, this.Height);
205202

206203
/// <inheritdoc/>
207204
public override string ToString() => $"SizeF [ Width={this.Width}, Height={this.Height} ]";

src/SixLabors.Core/SixLabors.Core.csproj

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,22 @@
1919
<Copyright>Copyright (c) Six Labors and contributors.</Copyright>
2020
<DebugType Condition="$(codecov) == 'true'">full</DebugType>
2121
<RootNamespace>SixLabors</RootNamespace>
22+
<LangVersion>7.3</LangVersion>
2223
</PropertyGroup>
2324

2425
<PropertyGroup>
2526
<CodeAnalysisRuleSet>..\SixLabors.ruleset</CodeAnalysisRuleSet>
2627
</PropertyGroup>
2728

29+
<!-- TODO: Include .NETSTANDARD2.1 when released-->
2830
<PropertyGroup Condition=" $(TargetFramework.StartsWith('netcoreapp2')) ">
2931
<DefineConstants>$(DefineConstants);SUPPORTS_MATHF</DefineConstants>
3032
</PropertyGroup>
31-
33+
34+
<PropertyGroup Condition=" $(TargetFramework.StartsWith('netcoreapp2.1')) ">
35+
<DefineConstants>$(DefineConstants);SUPPORTS_HASHCODE</DefineConstants>
36+
</PropertyGroup>
37+
3238
<ItemGroup>
3339
<PackageReference Include="StyleCop.Analyzers" Version="1.1.0-beta004">
3440
<PrivateAssets>All</PrivateAssets>

0 commit comments

Comments
 (0)