Optimize line mapping initialization.
This commit is contained in:
@@ -16,16 +16,13 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.codegen.inline
|
package org.jetbrains.kotlin.codegen.inline
|
||||||
|
|
||||||
import com.intellij.openapi.application.ApplicationManager
|
import gnu.trove.TIntIntHashMap
|
||||||
import org.jetbrains.org.objectweb.asm.MethodVisitor
|
|
||||||
import org.jetbrains.org.objectweb.asm.Label
|
|
||||||
import java.util
|
|
||||||
import java.util.LinkedHashMap
|
|
||||||
import java.util.Collections
|
|
||||||
import java.util.ArrayList
|
|
||||||
import org.jetbrains.kotlin.codegen.SourceInfo
|
|
||||||
import org.jetbrains.kotlin.codegen.ClassBuilder
|
import org.jetbrains.kotlin.codegen.ClassBuilder
|
||||||
import kotlin.properties.Delegates
|
import org.jetbrains.kotlin.codegen.SourceInfo
|
||||||
|
import org.jetbrains.org.objectweb.asm.Label
|
||||||
|
import org.jetbrains.org.objectweb.asm.MethodVisitor
|
||||||
|
import java.util
|
||||||
|
import java.util.*
|
||||||
|
|
||||||
//TODO join parameter
|
//TODO join parameter
|
||||||
public class SMAPBuilder(val source: String,
|
public class SMAPBuilder(val source: String,
|
||||||
@@ -194,23 +191,24 @@ public open class DefaultSourceMapper(val sourceInfo: SourceInfo, override val p
|
|||||||
|
|
||||||
var fileMappings: LinkedHashMap<String, RawFileMapping> = linkedMapOf()
|
var fileMappings: LinkedHashMap<String, RawFileMapping> = linkedMapOf()
|
||||||
|
|
||||||
protected var origin: RawFileMapping by Delegates.notNull()
|
protected val origin: RawFileMapping
|
||||||
|
|
||||||
init {
|
init {
|
||||||
visitSource(sourceInfo.source, sourceInfo.pathOrCleanFQN)
|
val name = sourceInfo.source
|
||||||
//map interval
|
val path = sourceInfo.pathOrCleanFQN
|
||||||
(1..maxUsedValue).forEach {origin.mapLine(it, it - 1, true) }
|
origin = RawFileMapping(name, path)
|
||||||
|
origin.initRange(1, maxUsedValue)
|
||||||
|
fileMappings.put(createKey(name, path), origin)
|
||||||
|
lastVisited = origin
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun createKey(name: String, path: String) = "$name#$path"
|
||||||
|
|
||||||
override val resultMappings: List<FileMapping>
|
override val resultMappings: List<FileMapping>
|
||||||
get() = fileMappings.values().map { it.toFileMapping() }
|
get() = fileMappings.values().map { it.toFileMapping() }
|
||||||
|
|
||||||
override fun visitSource(name: String, path: String) {
|
override fun visitSource(name: String, path: String) {
|
||||||
lastVisited = fileMappings.getOrPut("$name#$path", { RawFileMapping(name, path) })
|
lastVisited = fileMappings.getOrPut(createKey(name, path), { RawFileMapping(name, path) })
|
||||||
//TEMPORARY HACK
|
|
||||||
if (fileMappings.size() == 1) {
|
|
||||||
origin = lastVisited!!
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun visitOrigin() {
|
override fun visitOrigin() {
|
||||||
@@ -264,7 +262,7 @@ class SMAP(val fileMappings: List<FileMapping>) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class RawFileMapping(val name: String, val path: String) {
|
class RawFileMapping(val name: String, val path: String) {
|
||||||
private val lineMappings = linkedMapOf<Int, Int>()
|
private val lineMappings = TIntIntHashMap()
|
||||||
private val rangeMappings = arrayListOf<RangeMapping>()
|
private val rangeMappings = arrayListOf<RangeMapping>()
|
||||||
|
|
||||||
private var lastMappedWithNewIndex = -1000;
|
private var lastMappedWithNewIndex = -1000;
|
||||||
@@ -277,14 +275,23 @@ class RawFileMapping(val name: String, val path: String) {
|
|||||||
return fileMapping
|
return fileMapping
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
rangeMappings.add(RangeMapping(start, start, end - start + 1))
|
||||||
|
lastMappedWithNewIndex = end
|
||||||
|
}
|
||||||
|
|
||||||
fun mapLine(source: Int, currentIndex: Int, isLastMapped: Boolean): Int {
|
fun mapLine(source: Int, currentIndex: Int, isLastMapped: Boolean): Int {
|
||||||
var dest = lineMappings[source]
|
var dest = lineMappings[source]
|
||||||
if (dest == null) {
|
if (dest == 0) { // line numbers are 1-based, so 0 is ok to indicate missing value
|
||||||
val rangeMapping: RangeMapping
|
val rangeMapping: RangeMapping
|
||||||
if (rangeMappings.isNotEmpty() && isLastMapped && couldFoldInRange(lastMappedWithNewIndex, source)) {
|
if (rangeMappings.isNotEmpty() && isLastMapped && couldFoldInRange(lastMappedWithNewIndex, source)) {
|
||||||
rangeMapping = rangeMappings.last()
|
rangeMapping = rangeMappings.last()
|
||||||
rangeMapping.range += source - lastMappedWithNewIndex
|
rangeMapping.range += source - lastMappedWithNewIndex
|
||||||
dest = lineMappings[lastMappedWithNewIndex]!! + source - lastMappedWithNewIndex
|
dest = lineMappings[lastMappedWithNewIndex] + source - lastMappedWithNewIndex
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
dest = currentIndex + 1
|
dest = currentIndex + 1
|
||||||
|
|||||||
Reference in New Issue
Block a user