DirectoryBasedStorage — speed up collapse macro

This commit is contained in:
Vladimir Krivosheev
2018-07-31 20:04:05 +02:00
parent 5fb10a36f1
commit 46b84323ff
2 changed files with 9 additions and 16 deletions
@@ -178,32 +178,21 @@ open class DirectoryBasedStorage(private val dir: Path,
}
private fun saveStates(dir: VirtualFile, states: StateMap) {
val storeElement = Element(FileStorageCoreUtil.COMPONENT)
for (fileName in states.keys()) {
if (!dirtyFileNames.contains(fileName)) {
continue
}
var element: Element? = null
try {
element = states.getElement(fileName) ?: continue
storage.pathMacroSubstitutor?.collapsePaths(element)
storeElement.setAttribute(FileStorageCoreUtil.NAME, storage.componentName!!)
storeElement.addContent(element)
val element = states.getElement(fileName) ?: continue
val file = dir.getOrCreateChild(fileName, this)
// we don't write xml prolog due to historical reasons (and should not in any case)
writeFile(null, this, file, createDataWriterForElement(storeElement), getOrDetectLineSeparator(file) ?: LineSeparator.getSystemLineSeparator(), false)
val macroManager = if (storage.pathMacroSubstitutor == null) null else (storage.pathMacroSubstitutor as TrackingPathMacroSubstitutorImpl).macroManager
writeFile(null, this, file, XmlDataWriter(FileStorageCoreUtil.COMPONENT, listOf(element), mapOf(FileStorageCoreUtil.NAME to storage.componentName!!), macroManager), getOrDetectLineSeparator(file) ?: LineSeparator.getSystemLineSeparator(), false)
}
catch (e: IOException) {
LOG.error(e)
}
finally {
if (element != null) {
element.detach()
}
}
}
}
@@ -207,7 +207,7 @@ abstract class XmlElementStorage protected constructor(val fileSpec: String,
}
}
private class XmlDataWriter(private val rootElementName: String?,
internal class XmlDataWriter(private val rootElementName: String?,
private val elements: List<Element>,
private val rootAttributes: Map<String, String>,
private val macroManager: PathMacroManager?) : StringDataWriter() {
@@ -230,7 +230,11 @@ private class XmlDataWriter(private val rootElementName: String?,
writer.append(entry.key)
writer.append('=')
writer.append('"')
writer.append(replacePathMap?.substitute(JDOMUtil.escapeText(entry.value, false, true), SystemInfoRt.isFileSystemCaseSensitive))
var value = entry.value
if (replacePathMap != null) {
value = replacePathMap.substitute(JDOMUtil.escapeText(value, false, true), SystemInfoRt.isFileSystemCaseSensitive)
}
writer.append(JDOMUtil.escapeText(value, false, true))
writer.append('"')
}