From 552582bd8ac841afb382b8cd045ab737130f2073 Mon Sep 17 00:00:00 2001 From: peter Date: Tue, 13 Nov 2018 19:20:41 +0100 Subject: [PATCH] expand chameleons under lock to avoid multiple threads doing the same work originally parsing was moved out of lock for IDEA-73793 which is no longer actual --- .../source/tree/LazyParseableElement.java | 36 +++++++++---------- 1 file changed, 17 insertions(+), 19 deletions(-) diff --git a/platform/core-impl/src/com/intellij/psi/impl/source/tree/LazyParseableElement.java b/platform/core-impl/src/com/intellij/psi/impl/source/tree/LazyParseableElement.java index 3fd453198208..4e9617714b0b 100644 --- a/platform/core-impl/src/com/intellij/psi/impl/source/tree/LazyParseableElement.java +++ b/platform/core-impl/src/com/intellij/psi/impl/source/tree/LazyParseableElement.java @@ -178,27 +178,25 @@ public class LazyParseableElement extends CompositeElement { CharSequence text; synchronized (lock) { if (myParsed) return; + text = myText.get(); assert text != null; - } - FileElement fileElement = TreeUtil.getFileElement(this); - if (fileElement == null) { - LOG.error("Chameleons must not be parsed till they're in file tree: " + this); - } - else { - fileElement.assertReadAccessAllowed(); - } + FileElement fileElement = TreeUtil.getFileElement(this); + if (fileElement == null) { + LOG.error("Chameleons must not be parsed till they're in file tree: " + this); + } + else { + fileElement.assertReadAccessAllowed(); + } - DebugUtil.performPsiModification("lazy-parsing", () -> { - TreeElement parsedNode = (TreeElement)((ILazyParseableElementTypeBase)getElementType()).parseContents(this); - assertTextLengthIntact(text, parsedNode); + if (rawFirstChild() != null) { + LOG.error("Reentrant parsing?"); + } - synchronized (lock) { - if (myParsed) return; - if (rawFirstChild() != null) { - LOG.error("Reentrant parsing?"); - } + DebugUtil.performPsiModification("lazy-parsing", () -> { + TreeElement parsedNode = (TreeElement)((ILazyParseableElementTypeBase)getElementType()).parseContents(this); + assertTextLengthIntact(text, parsedNode); if (parsedNode != null) { setChildren(parsedNode); @@ -206,9 +204,9 @@ public class LazyParseableElement extends CompositeElement { myParsed = true; myText = new SoftReference<>(text); - } - }); - } + }); + } +} private void assertTextLengthIntact(CharSequence text, TreeElement child) { int length = 0;