Revert unnecessary synchronizes in ListWrapper

Usually the list we're wrapping is synchronized, so instead we'll ensure our code can be run concurrently.

There might be issues with other plugins and this change (but it's unlikely), open a issue if you see any of these after this change.
This commit is contained in:
Myles 2019-03-17 16:04:13 +00:00
parent d133ca4a0f
commit ee5eb59e42
2 changed files with 26 additions and 23 deletions

View File

@ -22,6 +22,8 @@ import java.util.List;
public class BukkitViaInjector implements ViaInjector {
private List<ChannelFuture> injectedFutures = new ArrayList<>();
private List<Pair<Field, Object>> injectedLists = new ArrayList<>();
private List<ChannelFuture> injectedFutures = new ConcurrentList<>();
private List<Pair<Field, Object>> injectedLists = new ConcurrentList<>();
@Override
public void inject() throws Exception {

View File

@ -19,43 +19,44 @@ public abstract class ListWrapper implements List {
}
@Override
public synchronized int size() {
public int size() {
return this.list.size();
}
@Override
public synchronized boolean isEmpty() {
public boolean isEmpty() {
return this.list.isEmpty();
}
@Override
public synchronized boolean contains(Object o) {
public boolean contains(Object o) {
return this.list.contains(o);
}
@Override
public synchronized Iterator iterator() {
public Iterator iterator() {
return listIterator();
}
@Override
public synchronized Object[] toArray() {
public Object[] toArray() {
return this.list.toArray();
}
@Override
public synchronized boolean add(Object o) {
public boolean add(Object o) {
handleAdd(o);
return this.list.add(o);
}
@Override
public synchronized boolean remove(Object o) {
public boolean remove(Object o) {
return this.list.remove(o);
}
@Override
public synchronized boolean addAll(Collection c) {
public boolean addAll(Collection c) {
for (Object o : c) {
handleAdd(o);
}
@ -63,7 +64,7 @@ public abstract class ListWrapper implements List {
}
@Override
public synchronized boolean addAll(int index, Collection c) {
public boolean addAll(int index, Collection c) {
for (Object o : c) {
handleAdd(o);
}
@ -71,72 +72,72 @@ public abstract class ListWrapper implements List {
}
@Override
public synchronized void clear() {
public void clear() {
this.list.clear();
}
@Override
public synchronized Object get(int index) {
public Object get(int index) {
return this.list.get(index);
}
@Override
public synchronized Object set(int index, Object element) {
public Object set(int index, Object element) {
return this.list.set(index, element);
}
@Override
public synchronized void add(int index, Object element) {
public void add(int index, Object element) {
this.list.add(index, element);
}
@Override
public synchronized Object remove(int index) {
public Object remove(int index) {
return this.list.remove(index);
}
@Override
public synchronized int indexOf(Object o) {
public int indexOf(Object o) {
return this.list.indexOf(o);
}
@Override
public synchronized int lastIndexOf(Object o) {
public int lastIndexOf(Object o) {
return this.list.lastIndexOf(o);
}
@Override
public synchronized ListIterator listIterator() {
public ListIterator listIterator() {
return this.list.listIterator();
}
@Override
public synchronized ListIterator listIterator(int index) {
public ListIterator listIterator(int index) {
return this.list.listIterator(index);
}
@Override
public synchronized List subList(int fromIndex, int toIndex) {
public List subList(int fromIndex, int toIndex) {
return this.list.subList(fromIndex, toIndex);
}
@Override
public synchronized boolean retainAll(Collection c) {
public boolean retainAll(Collection c) {
return this.list.retainAll(c);
}
@Override
public synchronized boolean removeAll(Collection c) {
public boolean removeAll(Collection c) {
return this.list.removeAll(c);
}
@Override
public synchronized boolean containsAll(Collection c) {
public boolean containsAll(Collection c) {
return this.list.containsAll(c);
}
@Override
public synchronized Object[] toArray(Object[] a) {
public Object[] toArray(Object[] a) {
return this.list.toArray(a);
}
}