From 225e90bbdf25c5b6e8e0324fedbae0c30a335b85 Mon Sep 17 00:00:00 2001 From: Michael Bogdanov Date: Tue, 19 Apr 2016 15:05:42 +0300 Subject: [PATCH] Removed redundant cache, small rename refactoring after removing --- .../jetbrains/kotlin/codegen/inline/SMAP.kt | 8 +++++-- .../jetbrains/kotlin/codegen/inline/SMAP2.kt | 23 +++---------------- .../idea/filters/KotlinExceptionFilter.kt | 2 +- 3 files changed, 10 insertions(+), 23 deletions(-) diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/SMAP.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/SMAP.kt index 1450e88866e..2843aaa7601 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/SMAP.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/SMAP.kt @@ -78,7 +78,7 @@ open class NestedSourceMapper( else { val rangeMapping = ranges[index] parent!!.visitSource(rangeMapping.parent!!.name, rangeMapping.parent!!.path) - parent!!.visitLineNumber(iv, rangeMapping.map(lineNumber), start) + parent!!.visitLineNumber(iv, rangeMapping.mapDestToSource(lineNumber), start) } } } @@ -345,10 +345,14 @@ data class RangeMapping(val source: Int, val dest: Int, var range: Int = 1) { return if (skip) true else dest <= destLine && destLine < dest + range } - fun map(destLine: Int): Int { + fun mapDestToSource(destLine: Int): Int { return if (skip) -1 else source + (destLine - dest) } + fun mapSourceToDest(sourceLine: Int): Int { + return if (skip) -1 else dest + (sourceLine - source) + } + object Comparator : java.util.Comparator { override fun compare(o1: RangeMapping, o2: RangeMapping): Int { if (o1 == o2) return 0 diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/SMAP2.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/SMAP2.kt index 13c07457ecf..fade3f99c6d 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/SMAP2.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/SMAP2.kt @@ -41,7 +41,7 @@ open class NestedSourceMapper( iv.visitLineNumber(mappedLineNumber, start) } else { val findMappingIfExists = findMappingIfExists(lineNumber)!! - val sourceLineNumber = findMappingIfExists.map(lineNumber) + val sourceLineNumber = findMappingIfExists.mapDestToSource(lineNumber) val visitLineNumber = parent.visitLineNumber(iv, lineNumber, start, LineNumberToMap(lineNumber, sourceLineNumber, findMappingIfExists.parent!!.name, findMappingIfExists.parent!!.path)) if (visitLineNumber > 0) { visited.put(lineNumber, visitLineNumber) @@ -150,7 +150,6 @@ open class DefaultSourceMapper @JvmOverloads constructor( } class RawFileMapping(val name: String, val path: String) { - private val lineMappings = TIntIntHashMap() private val rangeMappings = arrayListOf() private var lastMappedWithNewIndex = -1000 @@ -163,29 +162,18 @@ class RawFileMapping(val name: String, val path: String) { } fun initRange(start: Int, end: Int) { - assert(lineMappings.isEmpty) { "initRange should only be called for empty mapping" } - for (index in start..end) { - lineMappings.put(index, index) - } + assert(rangeMappings.isEmpty()) { "initRange should only be called for empty mapping" } rangeMappings.add(RangeMapping(start, start, end - start + 1)) lastMappedWithNewIndex = end } - fun mapLine(source: Int, currentIndex: Int, isLastMapped: Boolean): Int { - var dest = lineMappings[source] - if (dest == 0) { // line numbers are 1-based, so 0 is ok to indicate missing value - dest = mapNewLineNumber(source, currentIndex, isLastMapped) - } - return dest - } - fun mapNewLineNumber(source: Int, currentIndex: Int, isLastMapped: Boolean): Int { val dest: Int val rangeMapping: RangeMapping if (rangeMappings.isNotEmpty() && isLastMapped && couldFoldInRange(lastMappedWithNewIndex, source)) { rangeMapping = rangeMappings.last() rangeMapping.range += source - lastMappedWithNewIndex - dest = lineMappings[lastMappedWithNewIndex] + source - lastMappedWithNewIndex + dest = rangeMapping.mapSourceToDest(source) } else { dest = currentIndex + 1 @@ -193,7 +181,6 @@ class RawFileMapping(val name: String, val path: String) { rangeMappings.add(rangeMapping) } - lineMappings.put(source, dest) lastMappedWithNewIndex = source return dest } @@ -201,10 +188,6 @@ class RawFileMapping(val name: String, val path: String) { fun mapNewInterval(source: Int, dest: Int, range: Int) { val rangeMapping = RangeMapping(source, dest, range) rangeMappings.add(rangeMapping) - - (source..(source + range - 1)).forEach { - lineMappings.put(source, dest) - } } private fun couldFoldInRange(first: Int, second: Int): Boolean { diff --git a/idea/src/org/jetbrains/kotlin/idea/filters/KotlinExceptionFilter.kt b/idea/src/org/jetbrains/kotlin/idea/filters/KotlinExceptionFilter.kt index 2c26660fc81..3d439808a06 100644 --- a/idea/src/org/jetbrains/kotlin/idea/filters/KotlinExceptionFilter.kt +++ b/idea/src/org/jetbrains/kotlin/idea/filters/KotlinExceptionFilter.kt @@ -122,7 +122,7 @@ class KotlinExceptionFilter(private val searchScope: GlobalSearchScope) : Filter val newJvmName = JvmClassName.byInternalName(mappingInfo.path) val newSourceFile = DebuggerUtils.findSourceFileForClassIncludeLibrarySources(project, searchScope, newJvmName, mappingInfo.name) ?: return null - return OpenFileHyperlinkInfo(project, newSourceFile.virtualFile, mappingInfo.getIntervalIfContains(line)!!.map(line) - 1) + return OpenFileHyperlinkInfo(project, newSourceFile.virtualFile, mappingInfo.getIntervalIfContains(line)!!.mapDestToSource(line) - 1) } private fun readDebugInfo(bytes: ByteArray): String? {