DOM: performance

This commit is contained in:
Yann Cébron
2012-09-12 12:36:15 +02:00
parent ae94b8debc
commit 3ad9d0a3bb
2 changed files with 44 additions and 5 deletions
@@ -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<T extends AbstractDomChildDescription
myManager.getApplicationComponent().getVisitorDescription(visitor.getClass()).acceptElement(visitor, getProxy());
}
@SuppressWarnings("ForLoopReplaceableByForEach")
public void acceptChildren(DomElementVisitor visitor) {
ProgressManager.checkCanceled();
final DomElement element = getProxy();
for (final AbstractDomChildrenDescription description : getGenericInfo().getChildrenDescriptions()) {
for (final DomElement value : description.getValues(element)) {
List<? extends AbstractDomChildrenDescription> descriptions = getGenericInfo().getChildrenDescriptions();
for (int i = 0, descriptionsSize = descriptions.size(); i < descriptionsSize; i++) {
AbstractDomChildrenDescription description = descriptions.get(i);
List<? extends DomElement> values = description.getValues(element);
for (int j = 0, valuesSize = values.size(); j < valuesSize; j++) {
DomElement value = values.get(j);
value.accept(visitor);
}
}
@@ -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 <T extends DomElement> List<T> getChildrenOf(DomElement parent, final Class<T> type) {
final ArrayList<T> list = new ArrayList<T>();
final List<T> list = new SmartList<T>();
List<? extends AbstractDomChildrenDescription> 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<T>)description.getValues(parent)) {
List<T> values = (List<T>)description.getValues(parent);
for (int j = 0, valuesSize = values.size(); j < valuesSize; j++) {
T value = values.get(j);
if (value.exists()) {
list.add(value);
}