CompareArrays: retarget net10.0, split Article comparer, rename object-equality benchmarks - #2141
Open
vladimir-pecanac-main wants to merge 1 commit into
Conversation
…t-equality benchmarks - Retarget CompareArrays, BenchmarkRunner and Tests from net6.0 to net10.0. - BenchmarkDotNet 0.13.1 -> 0.15.8, MSTest 2.2.7 -> 3.10.4, Test.Sdk 16.11.0 -> 18.9.0, coverlet.collector 3.1.0 -> 10.0.1. - Article was its own IEqualityComparer<Article> and GetHashCode(Article obj) returned base.GetHashCode(), i.e. the hash of the comparer instance rather than of obj. Split it into a plain Article data class plus ArticleComparer : IEqualityComparer<Article> with a real GetHashCode combining Title and LastUpdate; EnumerableSequenceEqual(Article[], Article[]) now passes new ArticleComparer(). - Rename EnumerableEquals -> ObjectEquals and EnumerableReferenceEquals -> ObjectReferenceEquals in ArrayComparer, ArrayComparerBenchmark, Program and Tests. Both call sites are the unqualified Equals/ReferenceEquals resolving through the containing class from object; neither member is declared on Enumerable, and the benchmark's Method column is generated from these names. Build: 0 warnings, 0 errors. Tests: 14/14 passing on net10.0.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Supports the refresh of https://code-maze.com/csharp-compare-arrays/
CompareArrays,BenchmarkRunnerandTestsfromnet6.0tonet10.0.ArticleimplementedIEqualityComparer<Article>on the data class itself, andGetHashCode(Article obj)returnedbase.GetHashCode()- the hash of the comparer instance, not ofobj.SequenceEqualnever calls it, so the sample worked and the bug was invisible; the same class used withDistinct,GroupBy,HashSet<T>or a dictionary key would misbehave. Split into a plainArticledata class plusArticleComparer : IEqualityComparer<Article>with a realGetHashCodecombiningTitleandLastUpdate.EnumerableEquals->ObjectEqualsandEnumerableReferenceEquals->ObjectReferenceEqualsinArrayComparer,ArrayComparerBenchmark,ProgramandTests. NeitherEqualsnorReferenceEqualsis declared onSystem.Linq.Enumerable; both call sites are the unqualified form resolving through the containing class fromobject. BenchmarkDotNet generates itsMethodcolumn from these names, so the old names contradicted the article's own headings.Build: 0 warnings, 0 errors. Tests: 14/14 passing on net10.0.