From 5ee84808a09b95e96038d2de6d4b45d66d387b6c Mon Sep 17 00:00:00 2001 From: Dmitry Avdeev Date: Tue, 23 Jan 2018 13:24:49 +0300 Subject: [PATCH] IDEA-185180 RubyMine takes 400% of CPU during work with html file with inline styles --- .../com/intellij/xml/XmlNamespacesTest.java | 15 ++++++++++ xml/tests/testData/unusedNs/idproblem.html | 29 +++++++++++++++++++ .../intellij/xml/util/XmlRefCountHolder.java | 20 ++++++------- 3 files changed, 53 insertions(+), 11 deletions(-) create mode 100644 xml/tests/testData/unusedNs/idproblem.html diff --git a/xml/tests/src/com/intellij/xml/XmlNamespacesTest.java b/xml/tests/src/com/intellij/xml/XmlNamespacesTest.java index 2ab38e1ea16d..86fe7e5f6874 100644 --- a/xml/tests/src/com/intellij/xml/XmlNamespacesTest.java +++ b/xml/tests/src/com/intellij/xml/XmlNamespacesTest.java @@ -23,6 +23,7 @@ import com.intellij.ide.highlighter.XmlFileType; import com.intellij.javaee.ExternalResourceManagerExImpl; import com.intellij.openapi.application.Result; import com.intellij.openapi.command.WriteCommandAction; +import com.intellij.testFramework.PlatformTestUtil; import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase; import org.jetbrains.annotations.NotNull; @@ -254,6 +255,20 @@ public class XmlNamespacesTest extends LightCodeInsightFixtureTestCase { myFixture.testHighlighting(); } + public void testImplicitPrefixesPattern() { + myFixture.configureByText(XmlFileType.INSTANCE, "\n" + + " \n" + + " \n" + + ""); + myFixture.testHighlighting(); + } + + public void testPatternPerformanceProblem() { + myFixture.configureByFile("idproblem.html"); + PlatformTestUtil.startPerformanceTest("?", 100, () -> myFixture.doHighlighting()).assertTiming(); + } + private void doUnusedDeclarationTest(String text, String after, String name) { doUnusedDeclarationTest(text, after, name, true); } diff --git a/xml/tests/testData/unusedNs/idproblem.html b/xml/tests/testData/unusedNs/idproblem.html new file mode 100644 index 000000000000..42607bab2e37 --- /dev/null +++ b/xml/tests/testData/unusedNs/idproblem.html @@ -0,0 +1,29 @@ + + + + + +
+ + + + + + + +
+
+
+

+ ¡Bienvenido al equipo de +
Empresa! +

+
+
+
+ + \ No newline at end of file diff --git a/xml/xml-analysis-impl/src/com/intellij/xml/util/XmlRefCountHolder.java b/xml/xml-analysis-impl/src/com/intellij/xml/util/XmlRefCountHolder.java index 7671b6fe7112..07124f73bd50 100644 --- a/xml/xml-analysis-impl/src/com/intellij/xml/util/XmlRefCountHolder.java +++ b/xml/xml-analysis-impl/src/com/intellij/xml/util/XmlRefCountHolder.java @@ -21,6 +21,7 @@ import com.intellij.openapi.util.Key; import com.intellij.openapi.util.Pair; import com.intellij.openapi.util.UserDataCache; import com.intellij.psi.*; +import com.intellij.psi.html.HtmlTag; import com.intellij.psi.impl.source.resolve.reference.impl.providers.IdReferenceProvider; import com.intellij.psi.impl.source.xml.PossiblePrefixReference; import com.intellij.psi.impl.source.xml.SchemaPrefix; @@ -213,7 +214,7 @@ public class XmlRefCountHolder { myHolder.addUsedPrefix(tag.getNamespacePrefix()); myHolder.addUsedNamespace(tag.getNamespace()); String text = tag.getValue().getTrimmedText(); - detectPrefix(text); + detectPrefix(text, tag); super.visitXmlTag(tag); } @@ -257,10 +258,6 @@ public class XmlRefCountHolder { } } } - Matcher matcher = PREFIX_PATTERN.matcher(value.getText()); - while (matcher.find()) { - myHolder.addUsedPrefix(matcher.group()); - } } if (attributeDescriptor.hasIdRefType() && PsiTreeUtil.getChildOfType(value, OuterLanguageElement.class) == null) { @@ -269,15 +266,16 @@ public class XmlRefCountHolder { } String s = value.getValue(); - detectPrefix(s); + detectPrefix(s, tag); super.visitXmlAttributeValue(value); } - private void detectPrefix(String s) { - if (s != null) { - int pos = s.indexOf(':'); - if (pos > 0) { - myHolder.addUsedPrefix(s.substring(0, pos)); + private void detectPrefix(String s, XmlTag tag) { + if (s != null && !(tag instanceof HtmlTag) && s.length() < 1000) { + Matcher matcher = PREFIX_PATTERN.matcher(s); + while (matcher.find()) { + String group = matcher.group(); + myHolder.addUsedPrefix(group.substring(0, group.length() - 1)); } } }