Skip to content

Commit

Permalink
Fix forever loop (#260)
Browse files Browse the repository at this point in the history
* Fix forever loop

* Reviewer comments.
  • Loading branch information
johnml1135 authored Oct 18, 2024
1 parent 73a8d85 commit 8191be8
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/SIL.Machine/Corpora/ParallelTextCorpus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,7 @@ private class TargetCorpusEnumerator : DisposableBase, IEnumerator<TextRow>
private readonly ScrVers _sourceVersification;
private TextRow _current;
private bool _isEnumerating = false;
private bool _enumeratorHasMoreData = true;

public TargetCorpusEnumerator(
IEnumerator<TextRow> enumerator,
Expand Down Expand Up @@ -564,7 +565,7 @@ public bool MoveNext()
_enumerator.MoveNext();
_isEnumerating = true;
}
if (_verseRows.Count == 0 && _enumerator.Current != null)
if (_verseRows.Count == 0 && _enumerator.Current != null && _enumeratorHasMoreData)
CollectVerses();
if (_verseRows.Count > 0)
{
Expand All @@ -575,15 +576,16 @@ public bool MoveNext()
return false;
}

bool result = _enumerator.MoveNext();
_enumeratorHasMoreData = _enumerator.MoveNext();
_current = _enumerator.Current;
return result;
return _enumeratorHasMoreData;
}

public void Reset()
{
_enumerator.Reset();
_isEnumerating = false;
_enumeratorHasMoreData = true;
}

protected override void DisposeManagedResources()
Expand Down Expand Up @@ -635,7 +637,8 @@ private void CollectVerses()
if (!outOfOrder && scrRef.CompareTo(prevScrRef) < 0)
outOfOrder = true;
prevScrRef = scrRef;
} while (_enumerator.MoveNext());
_enumeratorHasMoreData = _enumerator.MoveNext();
} while (_enumeratorHasMoreData);

if (outOfOrder)
rowList.Sort((x, y) => x.Ref.CompareTo(y.Ref));
Expand Down

0 comments on commit 8191be8

Please sign in to comment.