From f9359096458c0b7bb3d844c661db5ba6b94255ff Mon Sep 17 00:00:00 2001 From: peter Date: Wed, 15 Jan 2014 20:39:07 +0100 Subject: [PATCH] case-insensitive CharSequenceHashingStrategy --- .../psi/impl/source/CharTableImpl.java | 2 +- .../text/CharSequenceHashingStrategy.java | 30 +++++++++---------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/platform/core-impl/src/com/intellij/psi/impl/source/CharTableImpl.java b/platform/core-impl/src/com/intellij/psi/impl/source/CharTableImpl.java index 4ee8df9d024a..179d344711ae 100644 --- a/platform/core-impl/src/com/intellij/psi/impl/source/CharTableImpl.java +++ b/platform/core-impl/src/com/intellij/psi/impl/source/CharTableImpl.java @@ -34,7 +34,7 @@ import java.lang.reflect.Modifier; */ public class CharTableImpl implements CharTable { private static final int INTERN_THRESHOLD = 40; // 40 or more characters long tokens won't be interned. - private static final CharSequenceHashingStrategy HASHER = new CharSequenceHashingStrategy(); + private static final CharSequenceHashingStrategy HASHER = CharSequenceHashingStrategy.CASE_SENSITIVE; private static final OpenTHashSet STATIC_ENTRIES = newStaticSet(); private final OpenTHashSet entries = new OpenTHashSet(10, 0.9f, HASHER); diff --git a/platform/util/src/com/intellij/util/text/CharSequenceHashingStrategy.java b/platform/util/src/com/intellij/util/text/CharSequenceHashingStrategy.java index 9933b2abe0ef..b19f6cd0aa26 100644 --- a/platform/util/src/com/intellij/util/text/CharSequenceHashingStrategy.java +++ b/platform/util/src/com/intellij/util/text/CharSequenceHashingStrategy.java @@ -15,6 +15,7 @@ */ package com.intellij.util.text; +import com.intellij.openapi.util.Comparing; import com.intellij.openapi.util.text.StringUtil; import gnu.trove.TObjectHashingStrategy; @@ -22,27 +23,26 @@ import gnu.trove.TObjectHashingStrategy; * @author max */ public final class CharSequenceHashingStrategy implements TObjectHashingStrategy { - private static final int COMPARISON_THRESHOLD = 5; + public static final CharSequenceHashingStrategy CASE_SENSITIVE = new CharSequenceHashingStrategy(true); + public static final CharSequenceHashingStrategy CASE_INSENSITIVE = new CharSequenceHashingStrategy(false); + private final boolean myCaseSensitive; + + @Deprecated + public CharSequenceHashingStrategy() { + this(true); + } + + private CharSequenceHashingStrategy(boolean caseSensitive) { + myCaseSensitive = caseSensitive; + } @Override public int computeHashCode(final CharSequence chars) { - return StringUtil.stringHashCode(chars); + return myCaseSensitive ? StringUtil.stringHashCode(chars) : StringUtil.stringHashCodeInsensitive(chars); } @Override public boolean equals(final CharSequence s1, final CharSequence s2) { - if(s1 == null || s2 == null) return false; - if(s1 == s2) return true; - int len = s1.length(); - if (len != s2.length()) return false; - - if (len > COMPARISON_THRESHOLD && s1 instanceof String && s2 instanceof String) { - return s1.equals(s2); - } - - for (int i = 0; i < len; i++) { - if (s1.charAt(i) != s2.charAt(i)) return false; - } - return true; + return Comparing.equal(s1, s2, myCaseSensitive); } }