Skip to content

Simplify ConcurrentReferenceHashMap #22387

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 15, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ private V put(@Nullable final K key, @Nullable final V value, final boolean over
return doTask(key, new Task<V>(TaskOption.RESTRUCTURE_BEFORE, TaskOption.RESIZE) {
@Override
@Nullable
protected V execute(@Nullable Reference<K, V> ref, @Nullable Entry<K, V> entry, @Nullable Entries entries) {
protected V execute(@Nullable Reference<K, V> ref, @Nullable Entry<K, V> entry, @Nullable Entries<V> entries) {
if (entry != null) {
V oldValue = entry.getValue();
if (overwriteExisting) {
Expand Down Expand Up @@ -530,15 +530,12 @@ public <T> T doTask(final int hash, @Nullable final Object key, final Task<T> ta
final Reference<K, V> head = this.references[index];
Reference<K, V> ref = findInChain(head, key, hash);
Entry<K, V> entry = (ref != null ? ref.get() : null);
Entries entries = new Entries() {
@Override
public void add(@Nullable V value) {
@SuppressWarnings("unchecked")
Entry<K, V> newEntry = new Entry<>((K) key, value);
Reference<K, V> newReference = Segment.this.referenceManager.createReference(newEntry, hash, head);
Segment.this.references[index] = newReference;
Segment.this.count.incrementAndGet();
}
Entries<V> entries = value -> {
@SuppressWarnings("unchecked")
Entry<K, V> newEntry = new Entry<>((K) key, value);
Reference<K, V> newReference = Segment.this.referenceManager.createReference(newEntry, hash, head);
Segment.this.references[index] = newReference;
Segment.this.count.incrementAndGet();
};
return task.execute(ref, entry, entries);
}
Expand Down Expand Up @@ -802,7 +799,7 @@ public boolean hasOption(TaskOption option) {
* @see #execute(Reference, Entry)
*/
@Nullable
protected T execute(@Nullable Reference<K, V> ref, @Nullable Entry<K, V> entry, @Nullable Entries entries) {
protected T execute(@Nullable Reference<K, V> ref, @Nullable Entry<K, V> entry, @Nullable Entries<V> entries) {
return execute(ref, entry);
}

Expand Down Expand Up @@ -830,15 +827,15 @@ private enum TaskOption {


/**
* Allows a task access to {@link Segment} entries.
* Allows a task access to {@link ConcurrentReferenceHashMap.Segment} entries.
*/
private abstract class Entries {
private interface Entries<V> {

/**
* Add a new entry with the specified value.
* @param value the value to add
*/
public abstract void add(@Nullable V value);
void add(@Nullable V value);
}


Expand Down