Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit dcdd3fb

Browse files
committed
Fix startIndex not working
1 parent c2de97e commit dcdd3fb

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

‎src/AlgorithmForce.Searching/Deferred/EnumerableExtensions.cs‎

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,10 +149,17 @@ public static int IndexOf<T>(this IEnumerable<T> s, IReadOnlyList<T> t, int star
149149
internal static int IndexOf<T>(this IEnumerable<T> s, T t, int startIndex, IEqualityComparer<T> comparer)
150150
where T : IEquatable<T>
151151
{
152-
foreach(var e in s)
152+
var offset = startIndex + 1;
153+
154+
using (var enumerator = s.GetEnumerator())
153155
{
154-
if (comparer.Equals(e, t)) return startIndex;
155-
startIndex++;
156+
while (Skip(enumerator, offset) != null)
157+
{
158+
if (comparer.Equals(t, enumerator.Current)) return startIndex;
159+
160+
startIndex++;
161+
offset = 1;
162+
}
156163
}
157164
return -1;
158165
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /