Browse Source

[SL.Core] Remove private implementations of GetHashCode (and it's call overhead)

pull/1087/head
Jason Nelson 8 years ago
parent
commit
1729bd662b
  1. 6
      src/SixLabors.Core/Primitives/Point.cs
  2. 16
      src/SixLabors.Core/Primitives/PointF.cs
  3. 19
      src/SixLabors.Core/Primitives/Rectangle.cs
  4. 41
      src/SixLabors.Core/Primitives/RectangleF.cs
  5. 4
      src/SixLabors.Core/Primitives/SizeF.cs

6
src/SixLabors.Core/Primitives/Point.cs

@ -258,7 +258,10 @@ namespace SixLabors.Primitives
public void Offset(Point point) => this.Offset(point.X, point.Y);
/// <inheritdoc/>
public override int GetHashCode() => this.GetHashCode(this);
public override int GetHashCode()
{
return HashHelpers.Combine(this.X.GetHashCode(), this.Y.GetHashCode());
}
/// <inheritdoc/>
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());
}
}

16
src/SixLabors.Core/Primitives/PointF.cs

@ -267,7 +267,10 @@ namespace SixLabors.Primitives
public void Offset(PointF point) => this.Offset(point.X, point.Y);
/// <inheritdoc/>
public override int GetHashCode() => this.GetHashCode(this);
public override int GetHashCode()
{
return HashHelpers.Combine(this.X.GetHashCode(), this.Y.GetHashCode());
}
/// <inheritdoc/>
public override string ToString()
@ -281,16 +284,5 @@ namespace SixLabors.Primitives
/// <inheritdoc/>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool Equals(PointF other) => this.X.Equals(other.X) && this.Y.Equals(other.Y);
/// <summary>
/// Returns the hash code for this instance.
/// </summary>
/// <param name="point">
/// The instance of <see cref="PointF"/> to return the hash code for.
/// </param>
/// <returns>
/// A 32-bit signed integer that is the hash code for this instance.
/// </returns>
private int GetHashCode(PointF point) => HashHelpers.Combine(point.X.GetHashCode(), point.Y.GetHashCode());
}
}

19
src/SixLabors.Core/Primitives/Rectangle.cs

@ -443,7 +443,14 @@ namespace SixLabors.Primitives
}
/// <inheritdoc/>
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());
}
/// <inheritdoc/>
public override string ToString()
@ -457,15 +464,5 @@ namespace SixLabors.Primitives
/// <inheritdoc/>
[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()
);
}
}
}

41
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;
}
/// <summary>
@ -132,10 +129,7 @@ namespace SixLabors.Primitives
public float Right
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get
{
return this.X + this.Width;
}
get => this.X + this.Width;
}
/// <summary>
@ -144,10 +138,7 @@ namespace SixLabors.Primitives
public float Bottom
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get
{
return this.Y + this.Height;
}
get => this.Y + this.Height;
}
/// <summary>
@ -156,10 +147,7 @@ namespace SixLabors.Primitives
public float Left
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get
{
return this.X;
}
get => this.X;
}
/// <summary>
@ -376,7 +364,14 @@ namespace SixLabors.Primitives
}
/// <inheritdoc/>
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());
}
/// <inheritdoc/>
public override string ToString()
@ -385,20 +380,10 @@ namespace SixLabors.Primitives
}
/// <inheritdoc/>
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);
/// <inheritdoc/>
[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()
);
}
}
}

4
src/SixLabors.Core/Primitives/SizeF.cs

@ -200,7 +200,7 @@ namespace SixLabors.Primitives
/// <inheritdoc/>
public override int GetHashCode()
{
return this.GetHashCode(this);
return HashHelpers.Combine(this.Width.GetHashCode(), this.Height.GetHashCode());
}
/// <inheritdoc/>
@ -224,7 +224,5 @@ namespace SixLabors.Primitives
/// <returns>Product of type SizeF.</returns>
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());
}
}
Loading…
Cancel
Save