mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-02-04 23:39:07 +07:00
[indexes] minor improvements in IdIndexEntryMapExternalizer
GitOrigin-RevId: dc222163aaf5ab691eceb6683719439129e837fd
This commit is contained in:
committed by
intellij-monorepo-bot
parent
2b777fc683
commit
df59e37c6d
@@ -24,6 +24,10 @@ public class IdEntryToScopeMapImpl extends AbstractMap<IdIndexEntry, Integer> im
|
||||
this(new Int2IntOpenHashMap());
|
||||
}
|
||||
|
||||
public IdEntryToScopeMapImpl(int initialCapacity) {
|
||||
this(new Int2IntOpenHashMap(initialCapacity));
|
||||
}
|
||||
|
||||
public IdEntryToScopeMapImpl(@NotNull Int2IntMap hashToScopeMask) {
|
||||
this.idHashToScopeMask = hashToScopeMask;
|
||||
}
|
||||
@@ -40,8 +44,10 @@ public class IdEntryToScopeMapImpl extends AbstractMap<IdIndexEntry, Integer> im
|
||||
|
||||
@Override
|
||||
public Integer get(Object key) {
|
||||
//noinspection deprecation
|
||||
return key instanceof IdIndexEntry entry ? idHashToScopeMask.get(entry.getWordHashCode()) : null;
|
||||
if (key instanceof IdIndexEntry entry) {
|
||||
return idHashToScopeMask.get(entry.getWordHashCode());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -54,7 +60,7 @@ public class IdEntryToScopeMapImpl extends AbstractMap<IdIndexEntry, Integer> im
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<IdIndexEntry> iterator() {
|
||||
public @NotNull Iterator<IdIndexEntry> iterator() {
|
||||
return new Iterator<>() {
|
||||
final IntIterator iterator = idHashToScopeMask.keySet().iterator();
|
||||
|
||||
@@ -88,7 +94,7 @@ public class IdEntryToScopeMapImpl extends AbstractMap<IdIndexEntry, Integer> im
|
||||
public Set<Entry<IdIndexEntry, Integer>> entrySet() {
|
||||
return new AbstractSet<>() {
|
||||
@Override
|
||||
public Iterator<Entry<IdIndexEntry, Integer>> iterator() {
|
||||
public @NotNull Iterator<Entry<IdIndexEntry, Integer>> iterator() {
|
||||
return new Iterator<>() {
|
||||
final ObjectIterator<Int2IntMap.Entry> iterator = idHashToScopeMask.int2IntEntrySet().iterator();
|
||||
|
||||
|
||||
@@ -3,7 +3,6 @@ package com.intellij.psi.impl.cache.impl.id;
|
||||
|
||||
import com.intellij.openapi.util.ThreadLocalCachedIntArray;
|
||||
import com.intellij.psi.search.UsageSearchContext;
|
||||
import com.intellij.util.indexing.InputMapExternalizer;
|
||||
import com.intellij.util.io.DataExternalizer;
|
||||
import com.intellij.util.io.DataInputOutputUtil;
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
||||
@@ -28,9 +27,9 @@ import java.util.Map;
|
||||
@ApiStatus.Internal
|
||||
public class IdIndexEntryMapExternalizer implements DataExternalizer<Map<IdIndexEntry, Integer>> {
|
||||
|
||||
private final InputMapExternalizer<IdIndexEntry, Integer> fallbackExternalizer;
|
||||
private final DataExternalizer<Map<IdIndexEntry, Integer>> fallbackExternalizer;
|
||||
|
||||
public IdIndexEntryMapExternalizer(@NotNull InputMapExternalizer<IdIndexEntry, Integer> externalizer) {
|
||||
public IdIndexEntryMapExternalizer(@NotNull DataExternalizer<Map<IdIndexEntry, Integer>> externalizer) {
|
||||
fallbackExternalizer = externalizer;
|
||||
}
|
||||
|
||||
@@ -39,16 +38,18 @@ public class IdIndexEntryMapExternalizer implements DataExternalizer<Map<IdIndex
|
||||
@Override
|
||||
public void save(@NotNull DataOutput out,
|
||||
@NotNull Map<IdIndexEntry, Integer> entries) throws IOException {
|
||||
int size = entries.size();
|
||||
DataInputOutputUtil.writeINT(out, size);
|
||||
|
||||
if (size == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!(entries instanceof IdEntryToScopeMap idToScopeMap)) {
|
||||
fallbackExternalizer.save(out, entries);
|
||||
return;
|
||||
}
|
||||
|
||||
int size = entries.size();
|
||||
DataInputOutputUtil.writeINT(out, size);
|
||||
if (size == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
Int2ObjectMap<IntSet> scopeMaskToHashes = new Int2ObjectOpenHashMap<>(8);
|
||||
idToScopeMap.forEach((idHash, scopeMask) -> {
|
||||
@@ -69,10 +70,13 @@ public class IdIndexEntryMapExternalizer implements DataExternalizer<Map<IdIndex
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<IdIndexEntry, Integer> read(@NotNull DataInput in) throws IOException {
|
||||
int pairs = DataInputOutputUtil.readINT(in);
|
||||
if (pairs == 0) return Collections.emptyMap();
|
||||
IdEntryToScopeMapImpl map = new IdEntryToScopeMapImpl();
|
||||
public @NotNull Map<IdIndexEntry, Integer> read(@NotNull DataInput in) throws IOException {
|
||||
int entriesCount = DataInputOutputUtil.readINT(in);
|
||||
if (entriesCount == 0) {
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
|
||||
IdEntryToScopeMapImpl map = new IdEntryToScopeMapImpl(entriesCount);
|
||||
while (((InputStream)in).available() > 0) {
|
||||
int occurenceMask = in.readByte();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user