From c0fc89b71542e67fb4bc5b96f1bb23f389e7b0cc Mon Sep 17 00:00:00 2001 From: Vladimir Krivosheev Date: Wed, 22 Aug 2018 17:49:24 +0200 Subject: [PATCH] avoid AttributeList creation if no attributes --- platform/util/src/org/jdom/JDOMInterner.java | 27 ++++++++------------ 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/platform/util/src/org/jdom/JDOMInterner.java b/platform/util/src/org/jdom/JDOMInterner.java index 0abee6cfbba6..550b898f1fcc 100644 --- a/platform/util/src/org/jdom/JDOMInterner.java +++ b/platform/util/src/org/jdom/JDOMInterner.java @@ -1,16 +1,4 @@ -// Copyright 2000-2017 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. +// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package org.jdom; import com.intellij.openapi.util.Comparing; @@ -19,6 +7,7 @@ import com.intellij.util.containers.StringInterner; import gnu.trove.TObjectHashingStrategy; import org.jetbrains.annotations.NotNull; +import java.util.Collections; import java.util.List; public class JDOMInterner { @@ -70,7 +59,7 @@ public class JDOMInterner { }); private static int computeAttributesHashCode(Element e) { - List attributes = e.getAttributes(); + List attributes = getAttributes(e); if (attributes instanceof ImmutableSameTypeAttributeList) { return attributes.hashCode(); } @@ -81,6 +70,12 @@ public class JDOMInterner { return result; } + @NotNull + private static List getAttributes(@NotNull Element e) { + // avoid AttributeList creation if no attributes + return e.hasAttributes() ? e.getAttributes() : Collections.emptyList(); + } + private static boolean attributesEqual(Element o1, Element o2) { if (o1 instanceof ImmutableElement) { return ((ImmutableElement)o1).attributesEqual(o2); @@ -88,8 +83,8 @@ public class JDOMInterner { if (o2 instanceof ImmutableElement) { return ((ImmutableElement)o2).attributesEqual(o1); } - List a1 = o1.getAttributes(); - List a2 = o2.getAttributes(); + List a1 = getAttributes(o1); + List a2 = getAttributes(o2); if (a1.size() != a2.size()) return false; for (int i=0; i