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:
Alexey Andreev
2017-07-09 14:09:20 +03:00
committed by Alexey Andreev
parent 83ec8aa918
commit 5a9adcca2d
5 changed files with 117 additions and 51 deletions
@@ -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")
}
}