[JS IR] Replace canonicalPath with absolutePath
Since canonicalPath is slow, replace it with absolutePath in SourceMaps and CompilationOutputs. ^KT-58187 Fixed
This commit is contained in:
committed by
Space Team
parent
1d9db1b9f8
commit
97024edf8a
+6
-3
@@ -35,7 +35,7 @@ abstract class CompilationOutputs {
|
|||||||
fun File.writeAsJsFile(out: CompilationOutputs) {
|
fun File.writeAsJsFile(out: CompilationOutputs) {
|
||||||
parentFile.mkdirs()
|
parentFile.mkdirs()
|
||||||
val jsMapFile = mapForJsFile
|
val jsMapFile = mapForJsFile
|
||||||
val jsFile = canonicalFile
|
val jsFile = normalizedAbsoluteFile
|
||||||
out.writeJsCode(jsFile, jsMapFile)
|
out.writeJsCode(jsFile, jsMapFile)
|
||||||
|
|
||||||
writtenFiles += jsFile
|
writtenFiles += jsFile
|
||||||
@@ -65,11 +65,14 @@ abstract class CompilationOutputs {
|
|||||||
return allTsDefinitions.toTypeScript(moduleName, moduleKind)
|
return allTsDefinitions.toTypeScript(moduleName, moduleKind)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private val File.normalizedAbsoluteFile
|
||||||
|
get() = absoluteFile.normalize()
|
||||||
|
|
||||||
private val File.mapForJsFile
|
private val File.mapForJsFile
|
||||||
get() = resolveSibling("$name.map").canonicalFile
|
get() = resolveSibling("$name.map").normalizedAbsoluteFile
|
||||||
|
|
||||||
private val File.dtsForJsFile
|
private val File.dtsForJsFile
|
||||||
get() = resolveSibling("$nameWithoutExtension.d.ts").canonicalFile
|
get() = resolveSibling("$nameWithoutExtension.d.ts").normalizedAbsoluteFile
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun File.copyModificationTimeFrom(from: File) {
|
private fun File.copyModificationTimeFrom(from: File) {
|
||||||
|
|||||||
@@ -8,20 +8,22 @@ package org.jetbrains.kotlin.js.sourceMap
|
|||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
||||||
class RelativePathCalculator(baseDir: File) {
|
class RelativePathCalculator(baseDir: File) {
|
||||||
private val baseDirPath = generateSequence(baseDir.canonicalFile) { it.parentFile }.toList().asReversed()
|
private fun File.getAllParents() = generateSequence(absoluteFile.normalize()) { it.parentFile }.toList().asReversed()
|
||||||
|
|
||||||
|
private val baseDirPath = baseDir.getAllParents()
|
||||||
|
|
||||||
fun calculateRelativePathTo(file: File): String? {
|
fun calculateRelativePathTo(file: File): String? {
|
||||||
val path = generateSequence(file.canonicalFile) { it.parentFile }.toList().asReversed()
|
val parents = file.getAllParents()
|
||||||
if (baseDirPath[0] != path[0]) return null
|
if (baseDirPath[0] != parents[0]) return null
|
||||||
|
|
||||||
val commonLength = baseDirPath.zip(path).takeWhile { (first, second) -> first == second }.size
|
val commonLength = baseDirPath.zip(parents).count { (first, second) -> first == second }
|
||||||
|
|
||||||
val sb = StringBuilder()
|
val sb = StringBuilder()
|
||||||
for (i in commonLength until baseDirPath.size) {
|
for (i in commonLength until baseDirPath.size) {
|
||||||
sb.append("../")
|
sb.append("../")
|
||||||
}
|
}
|
||||||
for (i in commonLength until path.size) {
|
for (i in commonLength until parents.size) {
|
||||||
sb.append(path[i].name).append('/')
|
sb.append(parents[i].name).append('/')
|
||||||
}
|
}
|
||||||
sb.setLength(sb.lastIndex)
|
sb.setLength(sb.lastIndex)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user