Moved check about old working variable not needed into common place
This commit is contained in:
@@ -82,8 +82,12 @@ fun match(loop: KtForExpression): ResultTransformationMatch? {
|
|||||||
for (matcher in MatcherRegistrar.sequenceMatchers) {
|
for (matcher in MatcherRegistrar.sequenceMatchers) {
|
||||||
val match = matcher.match(state)
|
val match = matcher.match(state)
|
||||||
if (match != null) {
|
if (match != null) {
|
||||||
|
val newState = match.newState
|
||||||
|
// check that old working variable is not needed anymore
|
||||||
|
if (state.workingVariable != newState.workingVariable && state.workingVariable.hasUsages(newState.statements)) return null
|
||||||
|
|
||||||
sequenceTransformations.addAll(match.transformations)
|
sequenceTransformations.addAll(match.transformations)
|
||||||
state = match.newState
|
state = newState
|
||||||
continue@MatchLoop
|
continue@MatchLoop
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
-1
@@ -61,7 +61,6 @@ class FlatMapTransformation(
|
|||||||
if (iterableType.checkIsSuperTypeOf(nestedSequenceType) == null) return null
|
if (iterableType.checkIsSuperTypeOf(nestedSequenceType) == null) return null
|
||||||
|
|
||||||
val nestedLoopBody = nestedLoop.body ?: return null
|
val nestedLoopBody = nestedLoop.body ?: return null
|
||||||
if (state.workingVariable.hasUsages(nestedLoopBody)) return null // workingVariable is still needed - cannot transform
|
|
||||||
|
|
||||||
val newWorkingVariable = nestedLoop.loopParameter ?: return null
|
val newWorkingVariable = nestedLoop.loopParameter ?: return null
|
||||||
val transformation = FlatMapTransformation(state.workingVariable, transform)
|
val transformation = FlatMapTransformation(state.workingVariable, transform)
|
||||||
|
|||||||
-1
@@ -49,7 +49,6 @@ class MapTransformation(
|
|||||||
val initializer = declaration.initializer ?: return null
|
val initializer = declaration.initializer ?: return null
|
||||||
if (declaration.hasWriteUsages()) return null
|
if (declaration.hasWriteUsages()) return null
|
||||||
val restStatements = state.statements.drop(1)
|
val restStatements = state.statements.drop(1)
|
||||||
if (state.workingVariable.hasUsages(restStatements)) return null // workingVariable is still needed - cannot transform to map()
|
|
||||||
|
|
||||||
val transformation = MapTransformation(state.workingVariable, initializer)
|
val transformation = MapTransformation(state.workingVariable, initializer)
|
||||||
val newState = state.copy(statements = restStatements, workingVariable = declaration)
|
val newState = state.copy(statements = restStatements, workingVariable = declaration)
|
||||||
|
|||||||
Reference in New Issue
Block a user