From 1729bd662bdabc5c1b722fbfe49bc54e1f236bf0 Mon Sep 17 00:00:00 2001 From: Jason Nelson Date: Fri, 24 Aug 2018 11:54:29 -0700 Subject: [PATCH] [SL.Core] Remove private implementations of GetHashCode (and it's call overhead) --- src/SixLabors.Core/Primitives/Point.cs | 6 ++- src/SixLabors.Core/Primitives/PointF.cs | 16 ++------ src/SixLabors.Core/Primitives/Rectangle.cs | 19 ++++------ src/SixLabors.Core/Primitives/RectangleF.cs | 41 +++++++-------------- src/SixLabors.Core/Primitives/SizeF.cs | 4 +- 5 files changed, 30 insertions(+), 56 deletions(-) diff --git a/src/SixLabors.Core/Primitives/Point.cs b/src/SixLabors.Core/Primitives/Point.cs index f302b82182..e42e2bf69d 100644 --- a/src/SixLabors.Core/Primitives/Point.cs +++ b/src/SixLabors.Core/Primitives/Point.cs @@ -258,7 +258,10 @@ namespace SixLabors.Primitives public void Offset(Point point) => this.Offset(point.X, point.Y); /// - public override int GetHashCode() => this.GetHashCode(this); + public override int GetHashCode() + { + return HashHelpers.Combine(this.X.GetHashCode(), this.Y.GetHashCode()); + } /// public override string ToString() @@ -277,6 +280,5 @@ namespace SixLabors.Primitives private static short LowInt16(int n) => unchecked((short)(n & 0xffff)); - private int GetHashCode(Point point) => HashHelpers.Combine(point.X.GetHashCode(), point.Y.GetHashCode()); } } \ No newline at end of file diff --git a/src/SixLabors.Core/Primitives/PointF.cs b/src/SixLabors.Core/Primitives/PointF.cs index 7c04315562..699cec8c69 100644 --- a/src/SixLabors.Core/Primitives/PointF.cs +++ b/src/SixLabors.Core/Primitives/PointF.cs @@ -267,7 +267,10 @@ namespace SixLabors.Primitives public void Offset(PointF point) => this.Offset(point.X, point.Y); /// - public override int GetHashCode() => this.GetHashCode(this); + public override int GetHashCode() + { + return HashHelpers.Combine(this.X.GetHashCode(), this.Y.GetHashCode()); + } /// public override string ToString() @@ -281,16 +284,5 @@ namespace SixLabors.Primitives /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Equals(PointF other) => this.X.Equals(other.X) && this.Y.Equals(other.Y); - - /// - /// Returns the hash code for this instance. - /// - /// - /// The instance of to return the hash code for. - /// - /// - /// A 32-bit signed integer that is the hash code for this instance. - /// - private int GetHashCode(PointF point) => HashHelpers.Combine(point.X.GetHashCode(), point.Y.GetHashCode()); } } \ No newline at end of file diff --git a/src/SixLabors.Core/Primitives/Rectangle.cs b/src/SixLabors.Core/Primitives/Rectangle.cs index b68732c40c..5b4ac10a7d 100644 --- a/src/SixLabors.Core/Primitives/Rectangle.cs +++ b/src/SixLabors.Core/Primitives/Rectangle.cs @@ -443,7 +443,14 @@ namespace SixLabors.Primitives } /// - public override int GetHashCode() => this.GetHashCode(this); + public override int GetHashCode() + { + return HashHelpers.Combine( + this.X.GetHashCode(), + this.Y.GetHashCode(), + this.Width.GetHashCode(), + this.Height.GetHashCode()); + } /// public override string ToString() @@ -457,15 +464,5 @@ namespace SixLabors.Primitives /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Equals(Rectangle other) => this.X == other.X && this.Y == other.Y && this.Width == other.Width && this.Height == other.Height; - - private int GetHashCode(Rectangle rectangle) - { - return HashHelpers.Combine( - rectangle.X.GetHashCode(), - rectangle.Y.GetHashCode(), - rectangle.Width.GetHashCode(), - rectangle.Height.GetHashCode() - ); - } } } \ No newline at end of file diff --git a/src/SixLabors.Core/Primitives/RectangleF.cs b/src/SixLabors.Core/Primitives/RectangleF.cs index a33d227e06..a7f46db0a7 100644 --- a/src/SixLabors.Core/Primitives/RectangleF.cs +++ b/src/SixLabors.Core/Primitives/RectangleF.cs @@ -120,10 +120,7 @@ namespace SixLabors.Primitives public float Top { [MethodImpl(MethodImplOptions.AggressiveInlining)] - get - { - return this.Y; - } + get => this.Y; } /// @@ -132,10 +129,7 @@ namespace SixLabors.Primitives public float Right { [MethodImpl(MethodImplOptions.AggressiveInlining)] - get - { - return this.X + this.Width; - } + get => this.X + this.Width; } /// @@ -144,10 +138,7 @@ namespace SixLabors.Primitives public float Bottom { [MethodImpl(MethodImplOptions.AggressiveInlining)] - get - { - return this.Y + this.Height; - } + get => this.Y + this.Height; } /// @@ -156,10 +147,7 @@ namespace SixLabors.Primitives public float Left { [MethodImpl(MethodImplOptions.AggressiveInlining)] - get - { - return this.X; - } + get => this.X; } /// @@ -376,7 +364,14 @@ namespace SixLabors.Primitives } /// - public override int GetHashCode() => this.GetHashCode(this); + public override int GetHashCode() + { + return HashHelpers.Combine( + this.X.GetHashCode(), + this.Y.GetHashCode(), + this.Width.GetHashCode(), + this.Height.GetHashCode()); + } /// public override string ToString() @@ -385,20 +380,10 @@ namespace SixLabors.Primitives } /// - public override bool Equals(object obj) => obj is RectangleF && this.Equals((RectangleF)obj); + public override bool Equals(object obj) => obj is RectangleF other && this.Equals(other); /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Equals(RectangleF other) => this.X.Equals(other.X) && this.Y.Equals(other.Y) && this.Width.Equals(other.Width) && this.Height.Equals(other.Height); - - private int GetHashCode(RectangleF rectangle) - { - return HashHelpers.Combine( - rectangle.X.GetHashCode(), - rectangle.Y.GetHashCode(), - rectangle.Width.GetHashCode(), - rectangle.Height.GetHashCode() - ); - } } } \ No newline at end of file diff --git a/src/SixLabors.Core/Primitives/SizeF.cs b/src/SixLabors.Core/Primitives/SizeF.cs index 13c6552ac3..365efdc2aa 100644 --- a/src/SixLabors.Core/Primitives/SizeF.cs +++ b/src/SixLabors.Core/Primitives/SizeF.cs @@ -200,7 +200,7 @@ namespace SixLabors.Primitives /// public override int GetHashCode() { - return this.GetHashCode(this); + return HashHelpers.Combine(this.Width.GetHashCode(), this.Height.GetHashCode()); } /// @@ -224,7 +224,5 @@ namespace SixLabors.Primitives /// Product of type SizeF. private static SizeF Multiply(SizeF size, float multiplier) => new SizeF(size.Width * multiplier, size.Height * multiplier); - - private int GetHashCode(SizeF size) => HashHelpers.Combine(size.Width.GetHashCode(), size.Height.GetHashCode()); } } \ No newline at end of file