mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-18 09:34:34 +07:00
removed dependency of ConcurrentIntObjectMap on its implementation
This commit is contained in:
@@ -60,7 +60,6 @@ import com.intellij.util.Processor;
|
||||
import com.intellij.util.containers.ConcurrentBitSet;
|
||||
import com.intellij.util.containers.ConcurrentIntObjectMap;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.intellij.util.containers.StripedLockIntObjectConcurrentHashMap;
|
||||
import com.intellij.util.io.storage.HeavyProcessLatch;
|
||||
import com.intellij.util.messages.MessageBus;
|
||||
import gnu.trove.*;
|
||||
@@ -678,7 +677,7 @@ public class RefResolveServiceImpl extends RefResolveService implements Runnable
|
||||
int forwardSize = 0;
|
||||
int backwardSize = 0;
|
||||
final TIntObjectHashMap<TIntArrayList> fileToBackwardIds = new TIntObjectHashMap<TIntArrayList>(fileToForwardIds.size());
|
||||
for (StripedLockIntObjectConcurrentHashMap.IntEntry<int[]> entry : fileToForwardIds.entries()) {
|
||||
for (ConcurrentIntObjectMap.IntEntry<int[]> entry : fileToForwardIds.entries()) {
|
||||
int fileId = entry.getKey();
|
||||
int[] forwardIds = entry.getValue();
|
||||
forwardSize += forwardIds.length;
|
||||
|
||||
@@ -15,8 +15,8 @@
|
||||
*/
|
||||
package com.intellij.openapi.util;
|
||||
|
||||
import com.intellij.util.containers.ConcurrentIntObjectMap;
|
||||
import com.intellij.util.containers.ConcurrentWeakValueIntObjectHashMap;
|
||||
import com.intellij.util.containers.StripedLockIntObjectConcurrentHashMap;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -109,7 +109,7 @@ public class Key<T> {
|
||||
*/
|
||||
@Nullable
|
||||
public static Key<?> findKeyByName(String name) {
|
||||
for (StripedLockIntObjectConcurrentHashMap.IntEntry<Key> key : allKeys.entries()) {
|
||||
for (ConcurrentIntObjectMap.IntEntry<Key> key : allKeys.entries()) {
|
||||
if (name.equals(key.getValue().myName)) {
|
||||
//noinspection unchecked
|
||||
return key.getValue();
|
||||
|
||||
@@ -17,6 +17,7 @@ package com.intellij.util.containers;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Enumeration;
|
||||
|
||||
/**
|
||||
@@ -42,7 +43,7 @@ public interface ConcurrentIntObjectMap<V> {
|
||||
boolean containsKey(int key);
|
||||
void clear();
|
||||
@NotNull
|
||||
Iterable<StripedLockIntObjectConcurrentHashMap.IntEntry<V>> entries();
|
||||
Iterable<IntEntry<V>> entries();
|
||||
|
||||
@NotNull
|
||||
int[] keys();
|
||||
@@ -58,5 +59,13 @@ public interface ConcurrentIntObjectMap<V> {
|
||||
boolean isEmpty();
|
||||
@NotNull
|
||||
Enumeration<V> elements();
|
||||
@NotNull
|
||||
Collection<V> values();
|
||||
V putIfAbsent(int key, @NotNull V value);
|
||||
boolean containsValue(@NotNull V value);
|
||||
|
||||
public interface IntEntry<V> {
|
||||
int getKey();
|
||||
@NotNull V getValue();
|
||||
}
|
||||
}
|
||||
|
||||
+30
-14
@@ -17,12 +17,11 @@
|
||||
package com.intellij.util.containers;
|
||||
|
||||
|
||||
import gnu.trove.THashSet;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.lang.ref.ReferenceQueue;
|
||||
import java.util.Enumeration;
|
||||
import java.util.Iterator;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Base class for concurrent int key -> (weak/soft) value:V map
|
||||
@@ -121,35 +120,35 @@ abstract class ConcurrentRefValueIntObjectHashMap<V> implements ConcurrentIntObj
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Iterable<StripedLockIntObjectConcurrentHashMap.IntEntry<V>> entries() {
|
||||
final Iterator<StripedLockIntObjectConcurrentHashMap.IntEntry<IntReference<V>>> entryIterator = myMap.entries().iterator();
|
||||
return new Iterable<StripedLockIntObjectConcurrentHashMap.IntEntry<V>>() {
|
||||
public Iterable<IntEntry<V>> entries() {
|
||||
final Iterator<IntEntry<IntReference<V>>> entryIterator = myMap.entries().iterator();
|
||||
return new Iterable<ConcurrentIntObjectMap.IntEntry<V>>() {
|
||||
@Override
|
||||
public Iterator<StripedLockIntObjectConcurrentHashMap.IntEntry<V>> iterator() {
|
||||
return new Iterator<StripedLockIntObjectConcurrentHashMap.IntEntry<V>>() {
|
||||
StripedLockIntObjectConcurrentHashMap.IntEntry<V> next = nextAliveEntry();
|
||||
public Iterator<ConcurrentIntObjectMap.IntEntry<V>> iterator() {
|
||||
return new Iterator<IntEntry<V>>() {
|
||||
IntEntry<V> next = nextAliveEntry();
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
return next != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public StripedLockIntObjectConcurrentHashMap.IntEntry<V> next() {
|
||||
public IntEntry<V> next() {
|
||||
if (!hasNext()) throw new NoSuchElementException();
|
||||
StripedLockIntObjectConcurrentHashMap.IntEntry<V> result = next;
|
||||
IntEntry<V> result = next;
|
||||
next = nextAliveEntry();
|
||||
return result;
|
||||
}
|
||||
|
||||
private StripedLockIntObjectConcurrentHashMap.IntEntry<V> nextAliveEntry() {
|
||||
private IntEntry<V> nextAliveEntry() {
|
||||
while (entryIterator.hasNext()) {
|
||||
StripedLockIntObjectConcurrentHashMap.IntEntry<IntReference<V>> entry = entryIterator.next();
|
||||
IntEntry<IntReference<V>> entry = entryIterator.next();
|
||||
final V v = entry.getValue().get();
|
||||
if (v == null) {
|
||||
continue;
|
||||
}
|
||||
final int key = entry.getKey();
|
||||
return new StripedLockIntObjectConcurrentHashMap.IntEntry<V>() {
|
||||
return new IntEntry<V>() {
|
||||
@Override
|
||||
public int getKey() {
|
||||
return key;
|
||||
@@ -221,4 +220,21 @@ abstract class ConcurrentRefValueIntObjectHashMap<V> implements ConcurrentIntObj
|
||||
IntReference<V> prev = myMap.putIfAbsent(key, createReference(key, value, myQueue));
|
||||
return prev == null ? null : prev.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<V> values() {
|
||||
Set<V> result = new THashSet<V>();
|
||||
ContainerUtil.addAll(result, elements());
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean containsValue(@NotNull V value) {
|
||||
for (IntEntry<IntReference<V>> entry : myMap.entries()) {
|
||||
if (value.equals(entry.getValue().get())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
+22
-11
@@ -16,12 +16,12 @@
|
||||
|
||||
package com.intellij.util.containers;
|
||||
|
||||
import com.intellij.openapi.util.Comparing;
|
||||
import gnu.trove.THashSet;
|
||||
import gnu.trove.TIntArrayList;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Enumeration;
|
||||
import java.util.Iterator;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.*;
|
||||
|
||||
/** similar to java.util.ConcurrentHashMap except:
|
||||
keys are ints
|
||||
@@ -29,7 +29,6 @@ import java.util.NoSuchElementException;
|
||||
-- using only one Segment
|
||||
-- eliminating unnecessary fields
|
||||
-- using one of 256 ReentrantLock for Segment statically pre-allocated in {@link StripedReentrantLocks}
|
||||
added hashing strategy argument
|
||||
made not Serializable
|
||||
*/
|
||||
public class StripedLockIntObjectConcurrentHashMap<V> implements ConcurrentIntObjectMap<V> {
|
||||
@@ -218,7 +217,13 @@ public class StripedLockIntObjectConcurrentHashMap<V> implements ConcurrentIntOb
|
||||
return new ValueIterator();
|
||||
}
|
||||
|
||||
/* ---------------- Iterator Support -------------- */
|
||||
@Override
|
||||
public Collection<V> values() {
|
||||
Set<V> result = new THashSet<V>();
|
||||
ContainerUtil.addAll(result, elements());
|
||||
return result;
|
||||
}
|
||||
/* ---------------- Iterator Support -------------- */
|
||||
|
||||
private class HashIterator {
|
||||
private int nextTableIndex = table.length - 1;
|
||||
@@ -279,12 +284,6 @@ public class StripedLockIntObjectConcurrentHashMap<V> implements ConcurrentIntOb
|
||||
}
|
||||
}
|
||||
|
||||
public interface IntEntry<V> {
|
||||
int getKey();
|
||||
@NotNull V getValue();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public Iterable<IntEntry<V>> entries() {
|
||||
@@ -485,6 +484,18 @@ public class StripedLockIntObjectConcurrentHashMap<V> implements ConcurrentIntOb
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean containsValue(@NotNull V value) {
|
||||
if (count != 0) { // read-volatile
|
||||
ValueIterator valueIterator = new ValueIterator();
|
||||
while (valueIterator.hasNext()) {
|
||||
V next = valueIterator.next();
|
||||
if (Comparing.equal(next, value)) return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean replace(int key, @NotNull V oldValue, @NotNull V newValue) {
|
||||
lock();
|
||||
|
||||
Reference in New Issue
Block a user