From b87c2a793dd6c79a1cd431088912bc8bdc8cd8f9 Mon Sep 17 00:00:00 2001 From: Marc-Andre Laperle Date: Fri, 21 Aug 2020 23:10:16 -0400 Subject: [PATCH] Bug 565553 - Improve performance of build command parsers with large number of files Do not pretty-format *.language.settings.xml files in the workspace plugin state area. These are not meant to be shared and looked by users so they do not really need to be pretty-formatted. This saves a lot of time for large projects with per-file language settings. For example, I have seen this save 30 sec on a test project during serialization. Change-Id: I27f8e0cfdc593f084d95bbed7aedb707570f1f6d Signed-off-by: Marc-Andre Laperle --- .../LanguageSettingsProvidersSerializer.java | 13 ++--------- .../eclipse/cdt/internal/core/XmlUtil.java | 23 ++++++++++++++++++- 2 files changed, 24 insertions(+), 12 deletions(-) diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsProvidersSerializer.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsProvidersSerializer.java index 02110ec446f..6c75983cc1b 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsProvidersSerializer.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsProvidersSerializer.java @@ -40,7 +40,6 @@ import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry; import org.eclipse.cdt.core.settings.model.ICProjectDescription; import org.eclipse.cdt.core.settings.model.ICSettingEntry; import org.eclipse.cdt.internal.core.XmlUtil; -import org.eclipse.cdt.internal.core.model.Util; import org.eclipse.cdt.internal.core.settings.model.CConfigurationSpecSettings; import org.eclipse.cdt.internal.core.settings.model.IInternalCCfgInfo; import org.eclipse.cdt.internal.core.settings.model.SettingsModelMessages; @@ -588,11 +587,7 @@ public class LanguageSettingsProvidersSerializer { try { serializingLockWsp.acquire(); - String eol = Util.getLineSeparator(uriStoreWsp); - if (eol == null) { - eol = Util.getDefaultLineSeparator(); - } - XmlUtil.serializeXml(doc, uriStoreWsp, eol); + XmlUtil.serializeXml(doc, uriStoreWsp); // manufacture events while inside the lock events = createLanguageSettingsChangeEvents(broadcastingWorkspaceProviders); } finally { @@ -915,11 +910,7 @@ public class LanguageSettingsProvidersSerializer { if (isWorkspaceStoreEmpty) { new java.io.File(uriStoreWsp).delete(); } else { - String eol = Util.getLineSeparator(uriStoreWsp); - if (eol == null) { - eol = Util.getDefaultLineSeparator(project); - } - XmlUtil.serializeXml(docStoreWsp, uriStoreWsp, eol); + XmlUtil.serializeXml(docStoreWsp, uriStoreWsp); } // manufacture the event only if serialization was successful diff --git a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/internal/core/XmlUtil.java b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/internal/core/XmlUtil.java index f89e557ec04..5dda1e8c309 100644 --- a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/internal/core/XmlUtil.java +++ b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/internal/core/XmlUtil.java @@ -279,6 +279,21 @@ public class XmlUtil { } } + /** + * Serialize XML Document into a file.
+ * Note: clients should synchronize access to this method. + * + * @param doc - DOM Document to serialize. + * @param uriLocation - URI of the file. + * + * @throws IOException in case of problems with file I/O + * @throws TransformerException in case of problems with XML output + */ + public static void serializeXml(Document doc, URI uriLocation) + throws IOException, TransformerException, CoreException { + serializeXmlInternal(doc, uriLocation, null); + } + /** * Serialize XML Document into a file.
* Note: clients should synchronize access to this method. @@ -286,18 +301,24 @@ public class XmlUtil { * @param doc - DOM Document to serialize. * @param uriLocation - URI of the file. * @param lineSeparator - line separator. + * Note: This will serialize in pretty format * * @throws IOException in case of problems with file I/O * @throws TransformerException in case of problems with XML output */ public static void serializeXml(Document doc, URI uriLocation, String lineSeparator) throws IOException, TransformerException, CoreException { + serializeXmlInternal(doc, uriLocation, lineSeparator); + } + + private static void serializeXmlInternal(Document doc, URI uriLocation, String lineSeparator) + throws IOException, TransformerException, CoreException { java.io.File storeFile = new java.io.File(uriLocation); if (!storeFile.exists()) { storeFile.createNewFile(); } - String utfString = toString(doc, lineSeparator); + String utfString = lineSeparator != null ? toString(doc, lineSeparator) : toString(doc); FileOutputStream output = getFileOutputStreamWorkaround(storeFile); output.write(utfString.getBytes(ENCODING_UTF_8));