From 3ad9d0a3bbf3ad62f91587ddeeff3970083e2885 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yann=20C=C3=A9bron?= Date: Wed, 12 Sep 2012 12:36:15 +0200 Subject: [PATCH] DOM: performance --- .../util/xml/impl/DomInvocationHandler.java | 24 ++++++++++++++++-- .../src/com/intellij/util/xml/DomUtil.java | 25 ++++++++++++++++--- 2 files changed, 44 insertions(+), 5 deletions(-) diff --git a/xml/dom-impl/src/com/intellij/util/xml/impl/DomInvocationHandler.java b/xml/dom-impl/src/com/intellij/util/xml/impl/DomInvocationHandler.java index eb71a4d6cec5..d44cc738baee 100644 --- a/xml/dom-impl/src/com/intellij/util/xml/impl/DomInvocationHandler.java +++ b/xml/dom-impl/src/com/intellij/util/xml/impl/DomInvocationHandler.java @@ -1,3 +1,18 @@ +/* + * Copyright 2000-2012 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.intellij.util.xml.impl; import com.intellij.openapi.diagnostic.Logger; @@ -404,11 +419,16 @@ public abstract class DomInvocationHandler descriptions = getGenericInfo().getChildrenDescriptions(); + for (int i = 0, descriptionsSize = descriptions.size(); i < descriptionsSize; i++) { + AbstractDomChildrenDescription description = descriptions.get(i); + List values = description.getValues(element); + for (int j = 0, valuesSize = values.size(); j < valuesSize; j++) { + DomElement value = values.get(j); value.accept(visitor); } } diff --git a/xml/dom-openapi/src/com/intellij/util/xml/DomUtil.java b/xml/dom-openapi/src/com/intellij/util/xml/DomUtil.java index d62d99752e75..5803c6c26df8 100644 --- a/xml/dom-openapi/src/com/intellij/util/xml/DomUtil.java +++ b/xml/dom-openapi/src/com/intellij/util/xml/DomUtil.java @@ -1,3 +1,18 @@ +/* + * Copyright 2000-2012 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.intellij.util.xml; import com.intellij.openapi.diagnostic.Logger; @@ -463,12 +478,16 @@ public class DomUtil { return Pair.create(startToken.getTextRange().shiftRight(-tag.getTextRange().getStartOffset()), (PsiElement)tag); } + @SuppressWarnings("ForLoopReplaceableByForEach") public static List getChildrenOf(DomElement parent, final Class type) { - final ArrayList list = new ArrayList(); + final List list = new SmartList(); List descriptions = parent.getGenericInfo().getChildrenDescriptions(); - for (AbstractDomChildrenDescription description : descriptions) { + for (int i = 0, descriptionsSize = descriptions.size(); i < descriptionsSize; i++) { + AbstractDomChildrenDescription description = descriptions.get(i); if (description.getType() instanceof Class && type.isAssignableFrom((Class)description.getType())) { - for (T value : (List)description.getValues(parent)) { + List values = (List)description.getValues(parent); + for (int j = 0, valuesSize = values.size(); j < valuesSize; j++) { + T value = values.get(j); if (value.exists()) { list.add(value); }