mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
case-insensitive CharSequenceHashingStrategy
This commit is contained in:
@@ -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<CharSequence> STATIC_ENTRIES = newStaticSet();
|
||||
|
||||
private final OpenTHashSet<CharSequence> entries = new OpenTHashSet<CharSequence>(10, 0.9f, HASHER);
|
||||
|
||||
@@ -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<CharSequence> {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user