Skip to content

Commit

Permalink
Merge pull request #648 from lahma/avoid-params-array-in-hash-code
Browse files Browse the repository at this point in the history
Avoid extra allocations in YamlScalarNode GetHashCode
  • Loading branch information
aaubry authored Nov 15, 2021
2 parents 961d6fc + d2599e8 commit 0d145bd
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 12 deletions.
10 changes: 0 additions & 10 deletions YamlDotNet/Core/HashCode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,6 @@ public static int CombineHashCodes(int h1, object? o2)
return CombineHashCodes(h1, GetHashCode(o2));
}

public static int CombineHashCodes(object? first, params object?[] others)
{
var hashCode = GetHashCode(first);
foreach (var other in others)
{
hashCode = CombineHashCodes(hashCode, other);
}
return hashCode;
}

private static int GetHashCode(object? obj)
{
return obj != null ? obj.GetHashCode() : 0;
Expand Down
2 changes: 1 addition & 1 deletion YamlDotNet/Core/TagName.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

namespace YamlDotNet.Core
{
public struct TagName : IEquatable<TagName>
public readonly struct TagName : IEquatable<TagName>
{
public static readonly TagName Empty = default;

Expand Down
2 changes: 1 addition & 1 deletion YamlDotNet/RepresentationModel/YamlScalarNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public override bool Equals(object? obj)
/// </returns>
public override int GetHashCode()
{
return CombineHashCodes(Tag, Value);
return CombineHashCodes(Tag.GetHashCode(), Value);
}

/// <summary>
Expand Down

0 comments on commit 0d145bd

Please sign in to comment.