mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
cleanup: use OpenTHashSet
This commit is contained in:
@@ -17,10 +17,10 @@
|
||||
package com.intellij.psi.impl.source;
|
||||
|
||||
import com.intellij.util.CharTable;
|
||||
import com.intellij.util.containers.OpenTHashSet;
|
||||
import com.intellij.util.text.CharArrayCharSequence;
|
||||
import com.intellij.util.text.CharArrayUtil;
|
||||
import com.intellij.util.text.CharSequenceHashingStrategy;
|
||||
import gnu.trove.THashSet;
|
||||
|
||||
/**
|
||||
* @author max
|
||||
@@ -28,9 +28,9 @@ import gnu.trove.THashSet;
|
||||
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 MyTHashSet STATIC_ENTRIES = new MyStaticTHashSet();
|
||||
private static final OpenTHashSet<CharSequence> STATIC_ENTRIES = newStaticSet();
|
||||
|
||||
private final MyTHashSet entries = new MyTHashSet();
|
||||
private final OpenTHashSet<CharSequence> entries = new OpenTHashSet<CharSequence>(10, 0.9f, HASHER);
|
||||
|
||||
public CharSequence intern(final CharSequence text) {
|
||||
if (text.length() > INTERN_THRESHOLD) return createSequence(text);
|
||||
@@ -72,115 +72,103 @@ public class CharTableImpl implements CharTable {
|
||||
}
|
||||
}
|
||||
|
||||
private static class MyTHashSet extends THashSet<CharSequence> {
|
||||
private MyTHashSet() {
|
||||
super(10, 0.9f, HASHER);
|
||||
}
|
||||
private static OpenTHashSet<CharSequence> newStaticSet() {
|
||||
final OpenTHashSet<CharSequence> r = new OpenTHashSet<CharSequence>(10, 0.9f, HASHER);
|
||||
r.add("==" );
|
||||
r.add("!=" );
|
||||
r.add("||" );
|
||||
r.add("++" );
|
||||
r.add("--" );
|
||||
|
||||
public int index(final CharSequence obj) {
|
||||
return super.index(obj);
|
||||
}
|
||||
r.add("<" );
|
||||
r.add("<=" );
|
||||
r.add("<<=" );
|
||||
r.add("<<" );
|
||||
r.add(">" );
|
||||
r.add("&" );
|
||||
r.add("&&" );
|
||||
|
||||
public CharSequence get(int index) {
|
||||
return (CharSequence)_set[index];
|
||||
}
|
||||
r.add("+=" );
|
||||
r.add("-=" );
|
||||
r.add("*=" );
|
||||
r.add("/=" );
|
||||
r.add("&=" );
|
||||
r.add("|=" );
|
||||
r.add("^=" );
|
||||
r.add("%=" );
|
||||
|
||||
r.add("(" );
|
||||
r.add(")" );
|
||||
r.add("{" );
|
||||
r.add("}" );
|
||||
r.add("[" );
|
||||
r.add("]" );
|
||||
r.add(";" );
|
||||
r.add("," );
|
||||
r.add("..." );
|
||||
r.add("." );
|
||||
|
||||
r.add("=" );
|
||||
r.add("!" );
|
||||
r.add("~" );
|
||||
r.add("?" );
|
||||
r.add(":" );
|
||||
r.add("+" );
|
||||
r.add("-" );
|
||||
r.add("*" );
|
||||
r.add("/" );
|
||||
r.add("|" );
|
||||
r.add("^" );
|
||||
r.add("%" );
|
||||
r.add("@" );
|
||||
|
||||
r.add(" " );
|
||||
r.add(" " );
|
||||
r.add(" " );
|
||||
r.add(" " );
|
||||
r.add(" " );
|
||||
r.add(" " );
|
||||
r.add(" " );
|
||||
r.add(" " );
|
||||
r.add(" " );
|
||||
r.add(" " );
|
||||
r.add(" " );
|
||||
r.add(" " );
|
||||
r.add(" " );
|
||||
r.add(" " );
|
||||
r.add(" " );
|
||||
r.add("\n" );
|
||||
r.add("\n " );
|
||||
r.add("\n " );
|
||||
r.add("\n " );
|
||||
r.add("\n " );
|
||||
r.add("\n " );
|
||||
r.add("\n " );
|
||||
r.add("\n " );
|
||||
r.add("\n " );
|
||||
|
||||
r.add("<");
|
||||
r.add(">");
|
||||
r.add("</");
|
||||
r.add("/>");
|
||||
r.add("\"");
|
||||
r.add("\'");
|
||||
r.add("<![CDATA[");
|
||||
r.add("]]>");
|
||||
r.add("<!--");
|
||||
r.add("-->");
|
||||
r.add("<!DOCTYPE");
|
||||
r.add("SYSTEM");
|
||||
r.add("PUBLIC");
|
||||
r.add("<?");
|
||||
r.add("?>");
|
||||
|
||||
r.add("<%");
|
||||
r.add("%>");
|
||||
r.add("<%=");
|
||||
r.add("<%@");
|
||||
r.add("${");
|
||||
r.add("");
|
||||
return r;
|
||||
}
|
||||
|
||||
private static class MyStaticTHashSet extends MyTHashSet {{
|
||||
add("==" );
|
||||
add("!=" );
|
||||
add("||" );
|
||||
add("++" );
|
||||
add("--" );
|
||||
|
||||
add("<" );
|
||||
add("<=" );
|
||||
add("<<=" );
|
||||
add("<<" );
|
||||
add(">" );
|
||||
add("&" );
|
||||
add("&&" );
|
||||
|
||||
add("+=" );
|
||||
add("-=" );
|
||||
add("*=" );
|
||||
add("/=" );
|
||||
add("&=" );
|
||||
add("|=" );
|
||||
add("^=" );
|
||||
add("%=" );
|
||||
|
||||
add("(" );
|
||||
add(")" );
|
||||
add("{" );
|
||||
add("}" );
|
||||
add("[" );
|
||||
add("]" );
|
||||
add(";" );
|
||||
add("," );
|
||||
add("..." );
|
||||
add("." );
|
||||
|
||||
add("=" );
|
||||
add("!" );
|
||||
add("~" );
|
||||
add("?" );
|
||||
add(":" );
|
||||
add("+" );
|
||||
add("-" );
|
||||
add("*" );
|
||||
add("/" );
|
||||
add("|" );
|
||||
add("^" );
|
||||
add("%" );
|
||||
add("@" );
|
||||
|
||||
add(" " );
|
||||
add(" " );
|
||||
add(" " );
|
||||
add(" " );
|
||||
add(" " );
|
||||
add(" " );
|
||||
add(" " );
|
||||
add(" " );
|
||||
add(" " );
|
||||
add(" " );
|
||||
add(" " );
|
||||
add(" " );
|
||||
add(" " );
|
||||
add(" " );
|
||||
add(" " );
|
||||
add("\n" );
|
||||
add("\n " );
|
||||
add("\n " );
|
||||
add("\n " );
|
||||
add("\n " );
|
||||
add("\n " );
|
||||
add("\n " );
|
||||
add("\n " );
|
||||
add("\n " );
|
||||
|
||||
add("<");
|
||||
add(">");
|
||||
add("</");
|
||||
add("/>");
|
||||
add("\"");
|
||||
add("\'");
|
||||
add("<![CDATA[");
|
||||
add("]]>");
|
||||
add("<!--");
|
||||
add("-->");
|
||||
add("<!DOCTYPE");
|
||||
add("SYSTEM");
|
||||
add("PUBLIC");
|
||||
add("<?");
|
||||
add("?>");
|
||||
|
||||
add("<%");
|
||||
add("%>");
|
||||
add("<%=");
|
||||
add("<%@");
|
||||
add("${");
|
||||
add("");
|
||||
}}
|
||||
}
|
||||
|
||||
@@ -15,32 +15,26 @@
|
||||
*/
|
||||
package com.intellij.util.containers;
|
||||
|
||||
import gnu.trove.THashSet;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* @author max
|
||||
*/
|
||||
public class StringInterner {
|
||||
private static class MySet extends THashSet<String> {
|
||||
public String intern(String name) {
|
||||
int idx = index(name);
|
||||
if (idx >= 0) {
|
||||
return (String)_set[idx];
|
||||
}
|
||||
|
||||
boolean added = add(name);
|
||||
assert added;
|
||||
|
||||
return name;
|
||||
}
|
||||
}
|
||||
|
||||
private final MySet mySet = new MySet();
|
||||
private final OpenTHashSet<String> mySet = new OpenTHashSet<String>();
|
||||
|
||||
@NotNull
|
||||
public String intern(@NotNull String name) {
|
||||
return mySet.intern(name);
|
||||
int idx = mySet.index(name);
|
||||
if (idx >= 0) {
|
||||
return mySet.get(idx);
|
||||
}
|
||||
|
||||
boolean added = mySet.add(name);
|
||||
assert added;
|
||||
|
||||
return name;
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
|
||||
@@ -7,7 +7,7 @@ import com.intellij.openapi.util.Comparing;
|
||||
import com.intellij.openapi.vcs.history.VcsRevisionNumber;
|
||||
import com.intellij.openapi.vcs.impl.ExcludedFileIndex;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import gnu.trove.THashSet;
|
||||
import com.intellij.util.containers.OpenTHashSet;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -28,7 +28,7 @@ public class LocalChangeListImpl extends LocalChangeList {
|
||||
|
||||
private boolean myIsDefault = false;
|
||||
private boolean myIsReadOnly = false;
|
||||
private ChangeHashSet myChangesBeforeUpdate;
|
||||
private OpenTHashSet<Change> myChangesBeforeUpdate;
|
||||
|
||||
public static LocalChangeListImpl createEmptyChangeListImpl(Project project, String name) {
|
||||
return new LocalChangeListImpl(project, name);
|
||||
@@ -131,7 +131,7 @@ public class LocalChangeListImpl extends LocalChangeList {
|
||||
synchronized Collection<Change> startProcessingChanges(final Project project, @Nullable final VcsDirtyScope scope) {
|
||||
createReadChangesCache();
|
||||
final Collection<Change> result = new ArrayList<Change>();
|
||||
myChangesBeforeUpdate = new ChangeHashSet(myChanges);
|
||||
myChangesBeforeUpdate = new OpenTHashSet<Change>(myChanges);
|
||||
final ExcludedFileIndex fileIndex = ExcludedFileIndex.getInstance(project);
|
||||
for (Change oldBoy : myChangesBeforeUpdate) {
|
||||
final ContentRevision before = oldBoy.getBeforeRevision();
|
||||
@@ -198,7 +198,7 @@ public class LocalChangeListImpl extends LocalChangeList {
|
||||
|
||||
@Nullable
|
||||
private Change findOldChange(final Change newChange) {
|
||||
Change oldChange = myChangesBeforeUpdate.getEqualChange(newChange);
|
||||
Change oldChange = myChangesBeforeUpdate.get(newChange);
|
||||
if (oldChange != null && sameBeforeRevision(oldChange, newChange) &&
|
||||
newChange.getFileStatus().equals(oldChange.getFileStatus())) {
|
||||
return oldChange;
|
||||
@@ -252,7 +252,7 @@ public class LocalChangeListImpl extends LocalChangeList {
|
||||
}
|
||||
|
||||
if (myChangesBeforeUpdate != null) {
|
||||
copy.myChangesBeforeUpdate = new ChangeHashSet(myChangesBeforeUpdate);
|
||||
copy.myChangesBeforeUpdate = new OpenTHashSet<Change>((Collection<Change>)myChangesBeforeUpdate);
|
||||
}
|
||||
|
||||
if (myReadChangesCache != null) {
|
||||
@@ -270,17 +270,4 @@ public class LocalChangeListImpl extends LocalChangeList {
|
||||
public void setId(String id) {
|
||||
myId = id;
|
||||
}
|
||||
|
||||
private static class ChangeHashSet extends THashSet<Change> {
|
||||
public ChangeHashSet(final Collection<? extends Change> changes) {
|
||||
super(changes);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
Change getEqualChange(Change other) {
|
||||
int aIndex = index(other);
|
||||
if (aIndex >= 0) return (Change)_set [aIndex];
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user