From cc549d3ae54a45c1b5c2c384cead6fed90755cf4 Mon Sep 17 00:00:00 2001 From: "Vitaliy.Bibaev" Date: Thu, 21 Dec 2017 18:28:38 +0300 Subject: [PATCH] Support chunked operation --- .../lib/sequence/KotlinSequencesSupport.kt | 2 + .../streams/kotlin/resolve/ChunkedResolver.kt | 39 +++++++++++++++++++ .../sequence/exec/sequence/outs/chunked.out | 18 ++++----- .../sequence/outs/chunkedWithTransform.out | 14 +++---- 4 files changed, 55 insertions(+), 18 deletions(-) create mode 100644 idea/idea-jvm/src/com/intellij/debugger/streams/kotlin/resolve/ChunkedResolver.kt diff --git a/idea/idea-jvm/src/com/intellij/debugger/streams/kotlin/lib/sequence/KotlinSequencesSupport.kt b/idea/idea-jvm/src/com/intellij/debugger/streams/kotlin/lib/sequence/KotlinSequencesSupport.kt index 0328141a44a..1ef29da4f1c 100644 --- a/idea/idea-jvm/src/com/intellij/debugger/streams/kotlin/lib/sequence/KotlinSequencesSupport.kt +++ b/idea/idea-jvm/src/com/intellij/debugger/streams/kotlin/lib/sequence/KotlinSequencesSupport.kt @@ -1,6 +1,7 @@ // Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.debugger.streams.kotlin.lib.sequence +import com.intellij.debugger.streams.kotlin.resolve.ChunkedResolver import com.intellij.debugger.streams.kotlin.resolve.MapNotNullResolver import com.intellij.debugger.streams.lib.IntermediateOperation import com.intellij.debugger.streams.lib.impl.* @@ -33,6 +34,7 @@ class KotlinSequencesSupport : LibrarySupportBase() { addIntermediateOperationsSupport(OrderBasedOperation("zipWithNext", PairMapResolver())) addIntermediateOperationsSupport(OrderBasedOperation("mapNotNull", MapNotNullResolver())) + addIntermediateOperationsSupport(OrderBasedOperation("chunked", ChunkedResolver())) } private fun filterOperations(vararg names: String): Array = diff --git a/idea/idea-jvm/src/com/intellij/debugger/streams/kotlin/resolve/ChunkedResolver.kt b/idea/idea-jvm/src/com/intellij/debugger/streams/kotlin/resolve/ChunkedResolver.kt new file mode 100644 index 00000000000..7db95ec5d95 --- /dev/null +++ b/idea/idea-jvm/src/com/intellij/debugger/streams/kotlin/resolve/ChunkedResolver.kt @@ -0,0 +1,39 @@ +// Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +package com.intellij.debugger.streams.kotlin.resolve + +import com.intellij.debugger.streams.resolve.ValuesOrderResolver +import com.intellij.debugger.streams.trace.TraceElement +import com.intellij.debugger.streams.trace.TraceInfo + +/** + * @author Vitaliy.Bibaev + */ +class ChunkedResolver : ValuesOrderResolver { + override fun resolve(info: TraceInfo): ValuesOrderResolver.Result { + val beforeIndex = info.valuesOrderBefore + val afterIndex = info.valuesOrderAfter + + val invertedOrder = mutableMapOf>() + val beforeTimes = beforeIndex.keys.sorted().toTypedArray() + val afterTimes = afterIndex.keys.sorted().toTypedArray() + + var beforeIx = 0 + for (afterTime in afterTimes) { + while (beforeIx < beforeTimes.size && beforeTimes[beforeIx] < afterTime) { + invertedOrder.computeIfAbsent(afterTime, { _ -> mutableListOf() }).add(beforeTimes[beforeIx]) + beforeIx += 1 + } + } + + val direct = mutableMapOf>() + val reverse = mutableMapOf>() + for ((timeAfter, elementAfter) in afterIndex) { + val before: List = invertedOrder[timeAfter] ?: emptyList() + val beforeElements = before.map { beforeIndex[it]!! } + beforeElements.forEach { direct[it] = listOf(elementAfter) } + reverse[elementAfter] = beforeElements + } + + return ValuesOrderResolver.Result.of(direct, reverse) + } +} \ No newline at end of file diff --git a/idea/testData/debugger/sequence/exec/sequence/outs/chunked.out b/idea/testData/debugger/sequence/exec/sequence/outs/chunked.out index 172c3648f29..05ce16f27b7 100644 --- a/idea/testData/debugger/sequence/exec/sequence/outs/chunked.out +++ b/idea/testData/debugger/sequence/exec/sequence/outs/chunked.out @@ -13,15 +13,15 @@ count after: nothing mappings for chunked direct: - 1 -> nothing - 2 -> nothing - 3 -> nothing - 4 -> nothing - 6 -> nothing - 7 -> nothing + 1 -> 5 + 2 -> 5 + 3 -> 5 + 4 -> 5 + 6 -> 8 + 7 -> 8 reverse: - nothing <- 5 - nothing <- 8 + 1,2,3,4 <- 5 + 6,7 <- 8 mappings for count direct: 5 -> nothing @@ -30,6 +30,4 @@ mappings for count empty Disconnected from the target VM -WRONG! - Process finished with exit code 0 diff --git a/idea/testData/debugger/sequence/exec/sequence/outs/chunkedWithTransform.out b/idea/testData/debugger/sequence/exec/sequence/outs/chunkedWithTransform.out index c5409c6aaa4..4218eff16fd 100644 --- a/idea/testData/debugger/sequence/exec/sequence/outs/chunkedWithTransform.out +++ b/idea/testData/debugger/sequence/exec/sequence/outs/chunkedWithTransform.out @@ -13,13 +13,13 @@ count after: nothing mappings for chunked direct: - 1 -> nothing - 2 -> nothing - 4 -> nothing - 5 -> nothing + 1 -> 3 + 2 -> 3 + 4 -> 6 + 5 -> 6 reverse: - nothing <- 3 - nothing <- 6 + 1,2 <- 3 + 4,5 <- 6 mappings for count direct: 3 -> nothing @@ -28,6 +28,4 @@ mappings for count empty Disconnected from the target VM -WRONG! - Process finished with exit code 0