From 46b84323ffd61ec696eb1ade468caedc2c498d45 Mon Sep 17 00:00:00 2001 From: Vladimir Krivosheev Date: Tue, 31 Jul 2018 19:02:01 +0200 Subject: [PATCH] =?UTF-8?q?DirectoryBasedStorage=20=E2=80=94=20speed=20up?= =?UTF-8?q?=20collapse=20macro?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/DirectoryBasedStorage.kt | 17 +++-------------- .../src/XmlElementStorage.kt | 8 ++++++-- 2 files changed, 9 insertions(+), 16 deletions(-) diff --git a/platform/configuration-store-impl/src/DirectoryBasedStorage.kt b/platform/configuration-store-impl/src/DirectoryBasedStorage.kt index 63226d8c3c91..a891d1d9cc61 100644 --- a/platform/configuration-store-impl/src/DirectoryBasedStorage.kt +++ b/platform/configuration-store-impl/src/DirectoryBasedStorage.kt @@ -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() - } - } } } diff --git a/platform/configuration-store-impl/src/XmlElementStorage.kt b/platform/configuration-store-impl/src/XmlElementStorage.kt index cefcd30a0ee0..4142af004fa4 100644 --- a/platform/configuration-store-impl/src/XmlElementStorage.kt +++ b/platform/configuration-store-impl/src/XmlElementStorage.kt @@ -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, private val rootAttributes: Map, 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('"') }