Fix performance bug, review feedback on indexer changes (#818)

This commit is contained in:
Nikolay Igotti
2017-08-29 16:12:44 +03:00
committed by GitHub
parent 2aa077e542
commit f74265126e
4 changed files with 37 additions and 25 deletions
@@ -216,6 +216,9 @@ internal class Context(config: KonanConfig) : KonanBackendContext(config) {
var phase: KonanPhase? = null
var depth: Int = 0
// Cache used for source offset->(line,column) mapping.
val fileEntryCache = mutableMapOf<String, SourceManager.FileEntry>()
protected fun separator(title: String) {
println("\n\n--- ${title} ----------------------\n")
}
@@ -93,9 +93,9 @@ class NaiveSourceBasedFileEntryImpl(override val name: String) : SourceManager.F
//-----------------------------------------------------------------------------//
class IrFileImpl(fileName: String) : IrFile {
class IrFileImpl(entry: SourceManager.FileEntry) : IrFile {
override val fileEntry = NaiveSourceBasedFileEntryImpl(fileName)
override val fileEntry = entry
//-------------------------------------------------------------------------//
@@ -30,6 +30,7 @@ import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.incremental.components.NoLookupLocation
import org.jetbrains.kotlin.ir.IrElement
import org.jetbrains.kotlin.ir.IrStatement
import org.jetbrains.kotlin.ir.SourceManager
import org.jetbrains.kotlin.ir.declarations.*
import org.jetbrains.kotlin.ir.descriptors.IrBuiltinOperatorDescriptorBase
import org.jetbrains.kotlin.ir.expressions.*
@@ -1433,8 +1434,15 @@ internal class CodeGeneratorVisitor(val context: Context, val lifetimes: Map<IrE
}
//-------------------------------------------------------------------------//
fun getFileEntry(sourceFileName: String): SourceManager.FileEntry {
// We must cache file entries, otherwise we reparse same file many times.
return context.fileEntryCache.getOrPut(sourceFileName) {
NaiveSourceBasedFileEntryImpl(sourceFileName)
}
}
private inner class ReturnableBlockScope(val returnableBlock: IrReturnableBlockImpl) : FileScope(IrFileImpl(returnableBlock.sourceFileName)) {
private inner class ReturnableBlockScope(val returnableBlock: IrReturnableBlockImpl) :
FileScope(IrFileImpl(getFileEntry(returnableBlock.sourceFileName))) {
var bbExit : LLVMBasicBlockRef? = null
var resultPhi : LLVMValueRef? = null