-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Remove Common Extensions HashCodeCombiner #43454
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using Xunit; | ||
|
|
||
| namespace Microsoft.Extensions.FileSystemGlobbing.Tests | ||
| { | ||
| public class FilePatternMatchTests | ||
| { | ||
| [Fact] | ||
| public void TestGetHashCode() | ||
| { | ||
| FilePatternMatch match1 = new FilePatternMatch("sub/sub2/bar/baz/three.txt", "sub2/bar/baz/three.txt"); | ||
| FilePatternMatch match2 = new FilePatternMatch("sub/sub2/bar/baz/three.txt", "sub2/bar/baz/three.txt"); | ||
| FilePatternMatch match3 = new FilePatternMatch("sub/sub2/bar/baz/one.txt", "sub2/bar/baz/three.txt"); | ||
eerhardt marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| FilePatternMatch match4 = new FilePatternMatch("sub/sub2/bar/baz/three.txt", "sub2/bar/baz/one.txt"); | ||
|
|
||
| Assert.Equal(match1.GetHashCode(), match2.GetHashCode()); | ||
| Assert.NotEqual(match1.GetHashCode(), match3.GetHashCode()); | ||
| Assert.NotEqual(match1.GetHashCode(), match4.GetHashCode()); | ||
|
|
||
| // FilePatternMatch is case insensitive | ||
| FilePatternMatch matchCase1 = new FilePatternMatch("Sub/Sub2/bar/baz/three.txt", "sub2/bar/baz/three.txt"); | ||
| FilePatternMatch matchCase2 = new FilePatternMatch("sub/sub2/bar/baz/three.txt", "Sub2/bar/baz/thrEE.txt"); | ||
| Assert.Equal(matchCase1.GetHashCode(), matchCase2.GetHashCode()); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void TestGetHashCodeWithNull() | ||
| { | ||
| FilePatternMatch match = new FilePatternMatch(null, null); | ||
| Assert.Equal(0, match.GetHashCode()); | ||
|
|
||
| int hash1 = new FilePatternMatch("non null", null).GetHashCode(); | ||
| int hash2 = new FilePatternMatch(null, "non null").GetHashCode(); | ||
| Assert.NotEqual(0, hash1); | ||
| Assert.NotEqual(0, hash2); | ||
| Assert.NotEqual(hash1, hash2); | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,9 +5,9 @@ | |
| using System.Collections; | ||
| using System.Collections.Generic; | ||
| using System.Diagnostics; | ||
| using System.Numerics.Hashing; | ||
| using System.Runtime.CompilerServices; | ||
| using System.Text; | ||
| using Microsoft.Extensions.Internal; | ||
|
|
||
| namespace Microsoft.Extensions.Primitives | ||
| { | ||
|
|
@@ -740,12 +740,12 @@ public override int GetHashCode() | |
| { | ||
| return Unsafe.As<string>(this[0])?.GetHashCode() ?? Count.GetHashCode(); | ||
| } | ||
| var hcc = default(HashCodeCombiner); | ||
| int hashCode = 0; | ||
|
||
| for (int i = 0; i < values.Length; i++) | ||
| { | ||
| hcc.Add(values[i]); | ||
| hashCode = HashHelpers.Combine(hashCode, values[i]?.GetHashCode() ?? 0); | ||
| } | ||
| return hcc.CombinedHash; | ||
| return hashCode; | ||
| } | ||
| else | ||
| { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.