diff --git a/xml/dom-impl/src/com/intellij/util/xml/impl/ChildrenDescriptionsHolder.java b/xml/dom-impl/src/com/intellij/util/xml/impl/ChildrenDescriptionsHolder.java index 8a3ad50a3924..259d7d7b5b7d 100644 --- a/xml/dom-impl/src/com/intellij/util/xml/impl/ChildrenDescriptionsHolder.java +++ b/xml/dom-impl/src/com/intellij/util/xml/impl/ChildrenDescriptionsHolder.java @@ -16,6 +16,7 @@ package com.intellij.util.xml.impl; import com.intellij.util.xml.XmlName; +import gnu.trove.THashMap; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -25,8 +26,9 @@ import java.util.*; * @author peter */ public class ChildrenDescriptionsHolder { - private final Map myMap = new TreeMap(); + private final Map myMap = new THashMap(); private final ChildrenDescriptionsHolder myDelegate; + private volatile List myCached = null; public ChildrenDescriptionsHolder(@Nullable final ChildrenDescriptionsHolder delegate) { myDelegate = delegate; @@ -38,6 +40,7 @@ public class ChildrenDescriptionsHolder { final T addDescription(@NotNull T t) { myMap.put(t.getXmlName(), t); + myCached = null; return t; } @@ -67,14 +70,28 @@ public class ChildrenDescriptionsHolder { return myDelegate != null ? myDelegate.findDescription(localName) : null; } + @NotNull final List getDescriptions() { final ArrayList result = new ArrayList(); dumpDescriptions(result); return result; } + private List getSortedDescriptions() { + List cached = myCached; + if (cached != null) { + return cached; + } + + cached = new ArrayList(myMap.values()); + Collections.sort(cached); + myCached = cached; + return cached; + } + + final void dumpDescriptions(Collection to) { - to.addAll(myMap.values()); + to.addAll(getSortedDescriptions()); if (myDelegate != null) { myDelegate.dumpDescriptions(to); }