-
Notifications
You must be signed in to change notification settings - Fork 332
Fix ISXB-1790: ArrayHelpers.Merge(IEqualityComparer) used wrong Equal… #2377
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
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -120,7 +120,7 @@ public static bool HaveDuplicateReferences<TFirst>(this TFirst[] first, int inde | |
| for (var i = 0; i < count; ++i) | ||
| { | ||
| var element = first[i]; | ||
| for (var n = i + 1; n < count - i; ++n) | ||
| for (var n = i + 1; n < count; ++n) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
While fixing the inner loop bound to for (var i = index; i < index + count; ++i)
{
var element = first[i];
for (var n = i + 1; n < index + count; ++n)
{
if (ReferenceEquals(element, first[n]))
return true;
}
}Consider adding a test case with a non-zero 🤖 Helpful? 👍/👎
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @K-Tone This looks like another bug that we should fix here. |
||
| { | ||
| if (ReferenceEquals(element, first[n])) | ||
| return true; | ||
|
|
@@ -552,7 +552,7 @@ public static TValue[] Merge<TValue>(TValue[] first, TValue[] second, IEqualityC | |
| for (var i = 0; i < second.Length; ++i) | ||
| { | ||
| var secondValue = second[i]; | ||
| if (!merged.Exists(x => comparer.Equals(secondValue))) | ||
| if (!merged.Exists(x => comparer.Equals(x, secondValue))) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
var alreadyExists = false;
for (var j = 0; j < merged.Count; ++j)
{
if (comparer.Equals(merged[j], secondValue))
{
alreadyExists = true;
break;
}
}
if (!alreadyExists)
merged.Add(secondValue);🤖 Helpful? 👍/👎
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should use a manual for loop here, should be addressed. |
||
| { | ||
| merged.Add(secondValue); | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider adding a
where TFirst : classconstraint to this method. Given the nameHaveDuplicateReferencesand the use ofReferenceEquals, this utility is clearly intended for reference types. Without a type constraint, passing value types to this method would cause boxing allocations on every comparison, which could significantly impact performance in hot paths.🤖 Helpful? 👍/👎
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree, the generic constraint is kind of required already. @K-Tone