Skip to content

Commit

Permalink
[FIR] Rewrite ResolutionStageRunner.processCandidate using while
Browse files Browse the repository at this point in the history
…instead of `forEach` loop
  • Loading branch information
KvanTTT authored and Space Team committed Dec 6, 2024
1 parent a933ff4 commit f6a80bc
Showing 1 changed file with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,13 @@ class ResolutionStageRunner {
val sink = CheckerSinkImpl(candidate, stopOnFirstError = stopOnFirstError)
var finished = false
sink.continuation = suspend {
candidate.callInfo.callKind.resolutionSequence.forEachIndexed { index, stage ->
if (index < candidate.passedStages) return@forEachIndexed
candidate.passedStages++
stage.check(candidate, candidate.callInfo, sink, context)
// Multiple runs on the same candidate are possible,
// that's why we have to skip already processed stages on the next run.
// Neither regular `for` loop nor iterating by index don't work here,
// because we have to start from the next unprocessed stage and mutate `Candidate.passedStages` on every iteration.
val resolutionSequence = candidate.callInfo.callKind.resolutionSequence
while (candidate.passedStages < resolutionSequence.size) {
resolutionSequence[candidate.passedStages++].check(candidate, candidate.callInfo, sink, context)
}
}.createCoroutineUnintercepted(completion = object : Continuation<Unit> {
override val context: CoroutineContext
Expand Down

0 comments on commit f6a80bc

Please sign in to comment.