Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
<ItemGroup>
<Reference Include="Microsoft.CodeAnalysis.Common" />
<Reference Include="Microsoft.CodeAnalysis.CSharp" />
<Reference Include="Microsoft.Bcl.HashCode" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System;
using System.Collections.Generic;
using Microsoft.Extensions.Internal;

namespace Microsoft.AspNetCore.Razor.Language
{
Expand Down Expand Up @@ -41,10 +42,10 @@ public virtual bool Equals(
/// <inheritdoc />
public virtual int GetHashCode(AllowedChildTagDescriptor descriptor)
{
var hash = new HashCode();
hash.Add(descriptor.Name ?? string.Empty, StringComparer.Ordinal);
var hash = HashCodeCombiner.Start();
hash.Add(descriptor.Name, StringComparer.Ordinal);

return hash.ToHashCode();
return hash.CombinedHash;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Extensions.Internal;

namespace Microsoft.AspNetCore.Razor.Language
{
Expand Down Expand Up @@ -55,12 +56,12 @@ public int GetHashCode(BoundAttributeDescriptor descriptor)
throw new ArgumentNullException(nameof(descriptor));
}

var hash = new HashCode();
hash.Add(descriptor.Kind ?? string.Empty, StringComparer.Ordinal);
hash.Add(descriptor.Name ?? string.Empty, StringComparer.Ordinal);
var hash = HashCodeCombiner.Start();
hash.Add(descriptor.Kind, StringComparer.Ordinal);
hash.Add(descriptor.Name, StringComparer.Ordinal);
hash.Add(descriptor.IsEditorRequired);
hash.Add(descriptor.TypeName ?? string.Empty, StringComparer.Ordinal);
hash.Add(descriptor.Documentation ?? string.Empty, StringComparer.Ordinal);
hash.Add(descriptor.TypeName, StringComparer.Ordinal);
hash.Add(descriptor.Documentation, StringComparer.Ordinal);

if (descriptor.BoundAttributeParameters != null)
{
Expand Down Expand Up @@ -88,7 +89,7 @@ public int GetHashCode(BoundAttributeDescriptor descriptor)
}
}

return hash.ToHashCode();
return hash.CombinedHash;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Extensions.Internal;

namespace Microsoft.AspNetCore.Razor.Language
{
Expand Down Expand Up @@ -49,13 +50,13 @@ public virtual int GetHashCode(BoundAttributeParameterDescriptor descriptor)
throw new ArgumentNullException(nameof(descriptor));
}

var hash = new HashCode();
hash.Add(descriptor.Kind ?? string.Empty, StringComparer.Ordinal);
hash.Add(descriptor.Name ?? string.Empty, StringComparer.Ordinal);
hash.Add(descriptor.TypeName ?? string.Empty, StringComparer.Ordinal);
var hash = HashCodeCombiner.Start();
hash.Add(descriptor.Kind, StringComparer.Ordinal);
hash.Add(descriptor.Name, StringComparer.Ordinal);
hash.Add(descriptor.TypeName, StringComparer.Ordinal);
hash.Add(descriptor.Metadata?.Count);

return hash.ToHashCode();
return hash.CombinedHash;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System;
using System.Globalization;
using Microsoft.Extensions.Internal;

namespace Microsoft.AspNetCore.Razor.Language.CodeGeneration
{
Expand Down Expand Up @@ -61,7 +62,11 @@ public bool Equals(LinePragma other)

public override int GetHashCode()
{
return HashCode.Combine(StartLineIndex, LineCount, FilePath);
var hash = HashCodeCombiner.Start();
hash.Add(StartLineIndex);
hash.Add(LineCount);
hash.Add(FilePath);
return hash;
}

public override string ToString()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// Licensed to the .NET Foundation under one or more agreements.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using Microsoft.Extensions.Internal;

namespace Microsoft.AspNetCore.Razor.Language
{
Expand Down Expand Up @@ -68,7 +69,7 @@ public override bool Equals(RazorDiagnostic obj)

public override int GetHashCode()
{
var hash = new HashCode();
var hash = HashCodeCombiner.Start();
hash.Add(Descriptor.GetHashCode());
hash.Add(Span.GetHashCode());

Expand All @@ -77,7 +78,7 @@ public override int GetHashCode()
hash.Add(Args[i]);
}

return hash.ToHashCode();
return hash;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Extensions.Internal;

namespace Microsoft.AspNetCore.Razor.Language
{
Expand Down Expand Up @@ -38,8 +39,8 @@ public int GetHashCode(DirectiveDescriptor descriptor)
throw new ArgumentNullException(nameof(descriptor));
}

var hash = new HashCode();
hash.Add(descriptor.Directive ?? string.Empty, StringComparer.Ordinal);
var hash = HashCodeCombiner.Start();
hash.Add(descriptor.Directive, StringComparer.Ordinal);
hash.Add(descriptor.Kind);

if (descriptor.Tokens != null)
Expand All @@ -50,7 +51,7 @@ public int GetHashCode(DirectiveDescriptor descriptor)
}
}

return hash.ToHashCode();
return hash.CombinedHash;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System;
using System.Collections.Generic;
using Microsoft.Extensions.Internal;

namespace Microsoft.AspNetCore.Razor.Language
{
Expand Down Expand Up @@ -33,7 +34,11 @@ public int GetHashCode(DirectiveTokenDescriptor descriptor)
throw new ArgumentNullException(nameof(descriptor));
}

return HashCode.Combine(descriptor.Kind, descriptor.Optional ? 1 : 0);
var hashCodeCombiner = HashCodeCombiner.Start();
hashCodeCombiner.Add(descriptor.Kind);
hashCodeCombiner.Add(descriptor.Optional ? 1 : 0);

return hashCodeCombiner.CombinedHash;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

#nullable enable

using System.Collections;
using System.Collections.Generic;
using System.Runtime.CompilerServices;

namespace Microsoft.Extensions.Internal
{
internal struct HashCodeCombiner
{
private long _combinedHash64;

public int CombinedHash
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get { return _combinedHash64.GetHashCode(); }
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
private HashCodeCombiner(long seed)
{
_combinedHash64 = seed;
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static implicit operator int(HashCodeCombiner self)
{
return self.CombinedHash;
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Add(int i)
{
_combinedHash64 = ((_combinedHash64 << 5) + _combinedHash64) ^ i;
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Add<T>(T? o)
{
Add(o?.GetHashCode() ?? 0);
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Add<TValue>(TValue value, IEqualityComparer<TValue> comparer)
{
var hashCode = value != null ? comparer.GetHashCode(value) : 0;
Add(hashCode);
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static HashCodeCombiner Start()
{
return new HashCodeCombiner(0x1505L);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Extensions.Internal;

namespace Microsoft.AspNetCore.Razor.Language.Legacy
{
Expand Down Expand Up @@ -49,14 +50,14 @@ public override bool Equals(object obj)
/// <inheritdoc />
public override int GetHashCode()
{
var combiner = new HashCode();
var combiner = HashCodeCombiner.Start();
combiner.Add(base.GetHashCode());
combiner.Add(LookupText ?? string.Empty, StringComparer.Ordinal);
combiner.Add(DirectiveText ?? string.Empty, StringComparer.Ordinal);
combiner.Add(TypePattern ?? string.Empty, StringComparer.Ordinal);
combiner.Add(AssemblyName ?? string.Empty, StringComparer.Ordinal);
combiner.Add(LookupText, StringComparer.Ordinal);
combiner.Add(DirectiveText, StringComparer.Ordinal);
combiner.Add(TypePattern, StringComparer.Ordinal);
combiner.Add(AssemblyName, StringComparer.Ordinal);

return combiner.ToHashCode();
return combiner.CombinedHash;
}

public override string ToString()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System;
using System.Collections.Generic;
using Microsoft.AspNetCore.Razor.Language.Syntax;
using Microsoft.Extensions.Internal;

namespace Microsoft.AspNetCore.Razor.Language.Legacy
{
Expand Down Expand Up @@ -59,7 +60,11 @@ public override bool Equals(object obj)
public override int GetHashCode()
{
// Hash code should include only immutable properties but Equals also checks the type.
return HashCode.Combine(TypeHashCode, AutoCompleteAtEndOfSpan);
var hashCodeCombiner = HashCodeCombiner.Start();
hashCodeCombiner.Add(TypeHashCode);
hashCodeCombiner.Add(AutoCompleteAtEndOfSpan);

return hashCodeCombiner.CombinedHash;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System;
using System.Text;
using Microsoft.Extensions.Internal;

namespace Microsoft.AspNetCore.Razor.Language.Legacy
{
Expand All @@ -26,7 +27,11 @@ public override bool Equals(object obj)

public override int GetHashCode()
{
return HashCode.Combine(base.GetHashCode(), Type);
var combiner = HashCodeCombiner.Start();
combiner.Add(base.GetHashCode());
combiner.Add(Type);

return combiner.CombinedHash;
}

public override string ToString()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.IO;
using System.Linq;
using Microsoft.AspNetCore.Razor.Language.Syntax;
using Microsoft.Extensions.Internal;

namespace Microsoft.AspNetCore.Razor.Language.Legacy
{
Expand Down Expand Up @@ -53,7 +54,10 @@ public override bool Equals(object obj)
public override int GetHashCode()
{
// Hash code should include only immutable properties and base has none.
return HashCode.Combine(AcceptTrailingDot);
var hashCodeCombiner = HashCodeCombiner.Start();
hashCodeCombiner.Add(AcceptTrailingDot);

return hashCodeCombiner;
}

protected override PartialParseResultInternal CanAcceptChange(SyntaxNode target, SourceChange change)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Globalization;
using Microsoft.Extensions.Internal;

namespace Microsoft.AspNetCore.Razor.Language.Legacy
{
Expand Down Expand Up @@ -33,7 +33,12 @@ public override bool Equals(object obj)

public override int GetHashCode()
{
return HashCode.Combine(Prefix, Value);
var hashCodeCombiner = HashCodeCombiner.Start();

hashCodeCombiner.Add(Prefix);
hashCodeCombiner.Add(Value);

return hashCodeCombiner;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System;
using System.Diagnostics;
using System.Globalization;
using Microsoft.Extensions.Internal;

namespace Microsoft.AspNetCore.Razor.Language.Legacy
{
Expand Down Expand Up @@ -44,7 +45,11 @@ public override bool Equals(object obj)

public override int GetHashCode()
{
return HashCode.Combine(Location, Value);
var hashCodeCombiner = HashCodeCombiner.Start();
hashCodeCombiner.Add(Location);
hashCodeCombiner.Add(Value);

return hashCodeCombiner.CombinedHash;
}

public override string ToString()
Expand Down
Loading