Browse Source

Update (hashCode * 397) pattern to use HashHelpers

af/merge-core
Jason Nelson 8 years ago
parent
commit
2fa5e3135e
  1. 2
      src/ImageSharp/MetaData/ImageProperty.cs
  2. 14
      src/ImageSharp/MetaData/Profiles/ICC/Curves/IccParametricCurve.cs
  3. 8
      src/ImageSharp/MetaData/Profiles/ICC/IccTagDataEntry.cs
  4. 10
      src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccCrdInfoTagDataEntry.cs
  5. 11
      src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccLut16TagDataEntry.cs
  6. 11
      src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccLut8TagDataEntry.cs
  7. 19
      src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccLutAToBTagDataEntry.cs
  8. 19
      src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccLutBToATagDataEntry.cs
  9. 13
      src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccMeasurementTagDataEntry.cs
  10. 14
      src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccNamedColor2TagDataEntry.cs
  11. 13
      src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccTextDescriptionTagDataEntry.cs
  12. 11
      src/ImageSharp/MetaData/Profiles/ICC/Various/IccClut.cs
  13. 15
      src/ImageSharp/MetaData/Profiles/ICC/Various/IccProfileDescription.cs

2
src/ImageSharp/MetaData/ImageProperty.cs

@ -106,7 +106,7 @@ namespace SixLabors.ImageSharp.MetaData
int hashCode = this.Name.GetHashCode(); int hashCode = this.Name.GetHashCode();
if (this.Value != null) if (this.Value != null)
{ {
hashCode = (hashCode * 397) ^ this.Value.GetHashCode(); hashCode = HashHelpers.Combine(hashCode, this.Value.GetHashCode());
} }
return hashCode; return hashCode;

14
src/ImageSharp/MetaData/Profiles/ICC/Curves/IccParametricCurve.cs

@ -157,13 +157,13 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc
unchecked unchecked
{ {
int hashCode = (int)this.Type; int hashCode = (int)this.Type;
hashCode = (hashCode * 397) ^ this.G.GetHashCode(); hashCode = HashHelpers.Combine(hashCode, this.G.GetHashCode());
hashCode = (hashCode * 397) ^ this.A.GetHashCode(); hashCode = HashHelpers.Combine(hashCode, this.A.GetHashCode());
hashCode = (hashCode * 397) ^ this.B.GetHashCode(); hashCode = HashHelpers.Combine(hashCode, this.B.GetHashCode());
hashCode = (hashCode * 397) ^ this.C.GetHashCode(); hashCode = HashHelpers.Combine(hashCode, this.C.GetHashCode());
hashCode = (hashCode * 397) ^ this.D.GetHashCode(); hashCode = HashHelpers.Combine(hashCode, this.D.GetHashCode());
hashCode = (hashCode * 397) ^ this.E.GetHashCode(); hashCode = HashHelpers.Combine(hashCode, this.E.GetHashCode());
hashCode = (hashCode * 397) ^ this.F.GetHashCode(); hashCode = HashHelpers.Combine(hashCode, this.F.GetHashCode());
return hashCode; return hashCode;
} }
} }

8
src/ImageSharp/MetaData/Profiles/ICC/IccTagDataEntry.cs

@ -64,12 +64,6 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc
} }
/// <inheritdoc/> /// <inheritdoc/>
public override int GetHashCode() public override int GetHashCode() => this.Signature.GetHashCode();
{
unchecked
{
return (int)this.Signature * 397;
}
}
} }
} }

10
src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccCrdInfoTagDataEntry.cs

@ -124,11 +124,11 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc
unchecked unchecked
{ {
int hashCode = base.GetHashCode(); int hashCode = base.GetHashCode();
hashCode = (hashCode * 397) ^ (this.PostScriptProductName?.GetHashCode() ?? 0); hashCode = HashHelpers.Combine(hashCode, this.PostScriptProductName?.GetHashCode() ?? 0);
hashCode = (hashCode * 397) ^ (this.RenderingIntent0Crd?.GetHashCode() ?? 0); hashCode = HashHelpers.Combine(hashCode, this.RenderingIntent0Crd?.GetHashCode() ?? 0);
hashCode = (hashCode * 397) ^ (this.RenderingIntent1Crd?.GetHashCode() ?? 0); hashCode = HashHelpers.Combine(hashCode, this.RenderingIntent1Crd?.GetHashCode() ?? 0);
hashCode = (hashCode * 397) ^ (this.RenderingIntent2Crd?.GetHashCode() ?? 0); hashCode = HashHelpers.Combine(hashCode, this.RenderingIntent2Crd?.GetHashCode() ?? 0);
hashCode = (hashCode * 397) ^ (this.RenderingIntent3Crd?.GetHashCode() ?? 0); hashCode = HashHelpers.Combine(hashCode, this.RenderingIntent3Crd?.GetHashCode() ?? 0);
return hashCode; return hashCode;
} }
} }

11
src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccLut16TagDataEntry.cs

@ -139,17 +139,14 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc
/// <inheritdoc/> /// <inheritdoc/>
public override int GetHashCode() public override int GetHashCode()
{
unchecked
{ {
int hashCode = base.GetHashCode(); int hashCode = base.GetHashCode();
hashCode = (hashCode * 397) ^ this.Matrix.GetHashCode(); hashCode = HashHelpers.Combine(hashCode, this.Matrix.GetHashCode());
hashCode = (hashCode * 397) ^ this.InputValues.GetHashCode(); hashCode = HashHelpers.Combine(hashCode, this.InputValues.GetHashCode());
hashCode = (hashCode * 397) ^ this.ClutValues.GetHashCode(); hashCode = HashHelpers.Combine(hashCode, this.ClutValues.GetHashCode());
hashCode = (hashCode * 397) ^ this.OutputValues.GetHashCode(); hashCode = HashHelpers.Combine(hashCode, this.OutputValues.GetHashCode());
return hashCode; return hashCode;
} }
}
private Matrix4x4 CreateMatrix(float[,] matrix) private Matrix4x4 CreateMatrix(float[,] matrix)
{ {

11
src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccLut8TagDataEntry.cs

@ -142,17 +142,14 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc
/// <inheritdoc/> /// <inheritdoc/>
public override int GetHashCode() public override int GetHashCode()
{
unchecked
{ {
int hashCode = base.GetHashCode(); int hashCode = base.GetHashCode();
hashCode = (hashCode * 397) ^ this.Matrix.GetHashCode(); hashCode = HashHelpers.Combine(hashCode, this.Matrix.GetHashCode());
hashCode = (hashCode * 397) ^ this.InputValues.GetHashCode(); hashCode = HashHelpers.Combine(hashCode, this.InputValues.GetHashCode());
hashCode = (hashCode * 397) ^ this.ClutValues.GetHashCode(); hashCode = HashHelpers.Combine(hashCode, this.ClutValues.GetHashCode());
hashCode = (hashCode * 397) ^ this.OutputValues.GetHashCode(); hashCode = HashHelpers.Combine(hashCode, this.OutputValues.GetHashCode());
return hashCode; return hashCode;
} }
}
private Matrix4x4 CreateMatrix(float[,] matrix) private Matrix4x4 CreateMatrix(float[,] matrix)
{ {

19
src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccLutAToBTagDataEntry.cs

@ -182,21 +182,18 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc
/// <inheritdoc/> /// <inheritdoc/>
public override int GetHashCode() public override int GetHashCode()
{
unchecked
{ {
int hashCode = base.GetHashCode(); int hashCode = base.GetHashCode();
hashCode = (hashCode * 397) ^ this.InputChannelCount; hashCode = HashHelpers.Combine(hashCode, this.InputChannelCount.GetHashCode());
hashCode = (hashCode * 397) ^ this.OutputChannelCount; hashCode = HashHelpers.Combine(hashCode, this.OutputChannelCount.GetHashCode());
hashCode = (hashCode * 397) ^ this.Matrix3x3.GetHashCode(); hashCode = HashHelpers.Combine(hashCode, this.Matrix3x3.GetHashCode());
hashCode = (hashCode * 397) ^ this.Matrix3x1.GetHashCode(); hashCode = HashHelpers.Combine(hashCode, this.Matrix3x1.GetHashCode());
hashCode = (hashCode * 397) ^ (this.ClutValues?.GetHashCode() ?? 0); hashCode = HashHelpers.Combine(hashCode, this.ClutValues?.GetHashCode() ?? 0);
hashCode = (hashCode * 397) ^ (this.CurveB?.GetHashCode() ?? 0); hashCode = HashHelpers.Combine(hashCode, this.CurveB?.GetHashCode() ?? 0);
hashCode = (hashCode * 397) ^ (this.CurveM?.GetHashCode() ?? 0); hashCode = HashHelpers.Combine(hashCode, this.CurveM?.GetHashCode() ?? 0);
hashCode = (hashCode * 397) ^ (this.CurveA?.GetHashCode() ?? 0); hashCode = HashHelpers.Combine(hashCode, this.CurveA?.GetHashCode() ?? 0);
return hashCode; return hashCode;
} }
}
private bool EqualsCurve(IccTagDataEntry[] thisCurves, IccTagDataEntry[] entryCurves) private bool EqualsCurve(IccTagDataEntry[] thisCurves, IccTagDataEntry[] entryCurves)
{ {

19
src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccLutBToATagDataEntry.cs

@ -182,21 +182,18 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc
/// <inheritdoc/> /// <inheritdoc/>
public override int GetHashCode() public override int GetHashCode()
{
unchecked
{ {
int hashCode = base.GetHashCode(); int hashCode = base.GetHashCode();
hashCode = (hashCode * 397) ^ this.InputChannelCount; hashCode = HashHelpers.Combine(hashCode, this.InputChannelCount.GetHashCode());
hashCode = (hashCode * 397) ^ this.OutputChannelCount; hashCode = HashHelpers.Combine(hashCode, this.OutputChannelCount.GetHashCode());
hashCode = (hashCode * 397) ^ this.Matrix3x3.GetHashCode(); hashCode = HashHelpers.Combine(hashCode, this.Matrix3x3.GetHashCode());
hashCode = (hashCode * 397) ^ this.Matrix3x1.GetHashCode(); hashCode = HashHelpers.Combine(hashCode, this.Matrix3x1.GetHashCode());
hashCode = (hashCode * 397) ^ (this.ClutValues?.GetHashCode() ?? 0); hashCode = HashHelpers.Combine(hashCode, this.ClutValues?.GetHashCode() ?? 0);
hashCode = (hashCode * 397) ^ (this.CurveB?.GetHashCode() ?? 0); hashCode = HashHelpers.Combine(hashCode, this.CurveB?.GetHashCode() ?? 0);
hashCode = (hashCode * 397) ^ (this.CurveM?.GetHashCode() ?? 0); hashCode = HashHelpers.Combine(hashCode, this.CurveM?.GetHashCode() ?? 0);
hashCode = (hashCode * 397) ^ (this.CurveA?.GetHashCode() ?? 0); hashCode = HashHelpers.Combine(hashCode, this.CurveA?.GetHashCode() ?? 0);
return hashCode; return hashCode;
} }
}
private bool EqualsCurve(IccTagDataEntry[] thisCurves, IccTagDataEntry[] entryCurves) private bool EqualsCurve(IccTagDataEntry[] thisCurves, IccTagDataEntry[] entryCurves)
{ {

13
src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccMeasurementTagDataEntry.cs

@ -105,17 +105,14 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc
/// <inheritdoc/> /// <inheritdoc/>
public override int GetHashCode() public override int GetHashCode()
{
unchecked
{ {
int hashCode = base.GetHashCode(); int hashCode = base.GetHashCode();
hashCode = (hashCode * 397) ^ (int)this.Observer; hashCode = HashHelpers.Combine(hashCode, this.Observer.GetHashCode());
hashCode = (hashCode * 397) ^ this.XyzBacking.GetHashCode(); hashCode = HashHelpers.Combine(hashCode, this.XyzBacking.GetHashCode());
hashCode = (hashCode * 397) ^ (int)this.Geometry; hashCode = HashHelpers.Combine(hashCode, this.Geometry.GetHashCode());
hashCode = (hashCode * 397) ^ this.Flare.GetHashCode(); hashCode = HashHelpers.Combine(hashCode, this.Flare.GetHashCode());
hashCode = (hashCode * 397) ^ (int)this.Illuminant; hashCode = HashHelpers.Combine(hashCode, this.Illuminant.GetHashCode());
return hashCode; return hashCode;
} }
} }
} }
}

14
src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccNamedColor2TagDataEntry.cs

@ -83,6 +83,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc
if (colors.Length > 0) if (colors.Length > 0)
{ {
coordinateCount = colors[0].DeviceCoordinates?.Length ?? 0; coordinateCount = colors[0].DeviceCoordinates?.Length ?? 0;
Guard.IsFalse(colors.Any(t => (t.DeviceCoordinates?.Length ?? 0) != coordinateCount), nameof(colors), "Device coordinate count must be the same for all colors"); Guard.IsFalse(colors.Any(t => (t.DeviceCoordinates?.Length ?? 0) != coordinateCount), nameof(colors), "Device coordinate count must be the same for all colors");
} }
@ -153,17 +154,14 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc
/// <inheritdoc/> /// <inheritdoc/>
public override int GetHashCode() public override int GetHashCode()
{
unchecked
{ {
int hashCode = base.GetHashCode(); int hashCode = base.GetHashCode();
hashCode = (hashCode * 397) ^ this.CoordinateCount; hashCode = HashHelpers.Combine(hashCode, this.CoordinateCount.GetHashCode());
hashCode = (hashCode * 397) ^ (this.Prefix?.GetHashCode() ?? 0); hashCode = HashHelpers.Combine(hashCode, this.Prefix?.GetHashCode() ?? 0);
hashCode = (hashCode * 397) ^ (this.Suffix?.GetHashCode() ?? 0); hashCode = HashHelpers.Combine(hashCode, this.Suffix?.GetHashCode() ?? 0);
hashCode = (hashCode * 397) ^ this.VendorFlags; hashCode = HashHelpers.Combine(hashCode, this.VendorFlags.GetHashCode());
hashCode = (hashCode * 397) ^ (this.Colors?.GetHashCode() ?? 0); hashCode = HashHelpers.Combine(hashCode, this.Colors.GetHashCode());
return hashCode; return hashCode;
} }
} }
} }
}

13
src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccTextDescriptionTagDataEntry.cs

@ -165,17 +165,14 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc
/// <inheritdoc /> /// <inheritdoc />
public override int GetHashCode() public override int GetHashCode()
{
unchecked
{ {
int hashCode = base.GetHashCode(); int hashCode = base.GetHashCode();
hashCode = (hashCode * 397) ^ (this.Ascii?.GetHashCode() ?? 0); hashCode = HashHelpers.Combine(hashCode, this.Ascii?.GetHashCode() ?? 0);
hashCode = (hashCode * 397) ^ (this.Unicode?.GetHashCode() ?? 0); hashCode = HashHelpers.Combine(hashCode, this.Unicode?.GetHashCode() ?? 0);
hashCode = (hashCode * 397) ^ (this.ScriptCode?.GetHashCode() ?? 0); hashCode = HashHelpers.Combine(hashCode, this.ScriptCode?.GetHashCode() ?? 0);
hashCode = (hashCode * 397) ^ (int)this.UnicodeLanguageCode; hashCode = HashHelpers.Combine(hashCode, this.UnicodeLanguageCode.GetHashCode());
hashCode = (hashCode * 397) ^ this.ScriptCodeCode.GetHashCode(); hashCode = HashHelpers.Combine(hashCode, this.ScriptCodeCode.GetHashCode());
return hashCode; return hashCode;
} }
} }
} }
}

11
src/ImageSharp/MetaData/Profiles/ICC/Various/IccClut.cs

@ -141,17 +141,14 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc
/// <inheritdoc/> /// <inheritdoc/>
public override int GetHashCode() public override int GetHashCode()
{
unchecked
{ {
int hashCode = this.Values.GetHashCode(); int hashCode = this.Values.GetHashCode();
hashCode = (hashCode * 397) ^ (int)this.DataType; hashCode = HashHelpers.Combine(hashCode, this.DataType.GetHashCode());
hashCode = (hashCode * 397) ^ this.InputChannelCount; hashCode = HashHelpers.Combine(hashCode, this.InputChannelCount.GetHashCode());
hashCode = (hashCode * 397) ^ this.OutputChannelCount; hashCode = HashHelpers.Combine(hashCode, this.OutputChannelCount.GetHashCode());
hashCode = (hashCode * 397) ^ this.GridPointCount.GetHashCode(); hashCode = HashHelpers.Combine(hashCode, this.GridPointCount.GetHashCode());
return hashCode; return hashCode;
} }
}
private bool EqualsValuesArray(IccClut other) private bool EqualsValuesArray(IccClut other)
{ {

15
src/ImageSharp/MetaData/Profiles/ICC/Various/IccProfileDescription.cs

@ -84,16 +84,13 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc
/// <inheritdoc /> /// <inheritdoc />
public override int GetHashCode() public override int GetHashCode()
{ {
unchecked int hashCode = this.DeviceManufacturer.GetHashCode();
{ hashCode = HashHelpers.Combine(hashCode, this.DeviceModel.GetHashCode());
int hashCode = (int)this.DeviceManufacturer; hashCode = HashHelpers.Combine(hashCode, this.DeviceAttributes.GetHashCode());
hashCode = (hashCode * 397) ^ (int)this.DeviceModel; hashCode = HashHelpers.Combine(hashCode, this.TechnologyInformation.GetHashCode());
hashCode = (hashCode * 397) ^ this.DeviceAttributes.GetHashCode(); hashCode = HashHelpers.Combine(hashCode, this.DeviceManufacturerInfo.GetHashCode());
hashCode = (hashCode * 397) ^ (int)this.TechnologyInformation; hashCode = HashHelpers.Combine(hashCode, this.DeviceModelInfo.GetHashCode());
hashCode = (hashCode * 397) ^ this.DeviceManufacturerInfo.GetHashCode();
hashCode = (hashCode * 397) ^ this.DeviceModelInfo.GetHashCode();
return hashCode; return hashCode;
} }
} }
} }
}

Loading…
Cancel
Save