Improve performance of JS tests
* Do not read protos for descriptors of stdlib and kotlin-tests repeatedly * Parse libraries lazily in inline, so that when no inline function exist in a test, we won't parse huge kotlin.js file * Speed-up source map parser
This commit is contained in:
committed by
Alexey Andreev
parent
83ec8aa918
commit
5a9adcca2d
@@ -22,16 +22,31 @@ class OffsetToSourceMapping(text: String) {
|
||||
private val data: IntArray
|
||||
|
||||
init {
|
||||
val lineSeparators = LINE_SEPARATOR.findAll(text).map { it.range.endInclusive + 1 }
|
||||
data = (sequenceOf(0) + lineSeparators).toList().toIntArray()
|
||||
var i = 0
|
||||
val lineSeparators = mutableListOf<Int>()
|
||||
lineSeparators += 0
|
||||
while (i < text.length) {
|
||||
val c = text[i++]
|
||||
val isNewLine = when (c) {
|
||||
'\r' -> {
|
||||
if (i < text.length && text[i] == '\n') {
|
||||
++i
|
||||
}
|
||||
true
|
||||
}
|
||||
'\n' -> true
|
||||
else -> false
|
||||
}
|
||||
if (isNewLine) {
|
||||
lineSeparators += i
|
||||
}
|
||||
}
|
||||
|
||||
data = lineSeparators.toIntArray()
|
||||
}
|
||||
|
||||
operator fun get(offset: Int): CodePosition {
|
||||
val lineNumber = data.binarySearch(offset).let { if (it >= 0) it else -it - 2 }
|
||||
return CodePosition(lineNumber, offset - data[lineNumber])
|
||||
}
|
||||
|
||||
private companion object {
|
||||
private val LINE_SEPARATOR = Regex("\\r\\n|\\r|\\n")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user