mirror of
https://github.com/PaperMC/Waterfall.git
synced 2024-11-25 03:35:18 +01:00
Don't aggressively trim LowMemorySets
This only add complexity.
This commit is contained in:
parent
2dd82be3f1
commit
6fc2170f21
@ -1,4 +1,4 @@
|
|||||||
From 5eca7dd60b1298b1c5f45fb5991329bb4f634a0b Mon Sep 17 00:00:00 2001
|
From 983fddb8db3706b766527f8328ed7556dbb58639 Mon Sep 17 00:00:00 2001
|
||||||
From: Techcable <Techcable@techcable.net>
|
From: Techcable <Techcable@techcable.net>
|
||||||
Date: Mon, 25 Apr 2016 23:46:00 -0700
|
Date: Mon, 25 Apr 2016 23:46:00 -0700
|
||||||
Subject: [PATCH] Reduce the overhead of lots and lots of teams with the same
|
Subject: [PATCH] Reduce the overhead of lots and lots of teams with the same
|
||||||
@ -11,14 +11,12 @@ Uses a sorted array to avoid the overhead of the hashset in a team.
|
|||||||
|
|
||||||
diff --git a/api/src/main/java/io/github/waterfallmc/waterfall/utils/LowMemorySet.java b/api/src/main/java/io/github/waterfallmc/waterfall/utils/LowMemorySet.java
|
diff --git a/api/src/main/java/io/github/waterfallmc/waterfall/utils/LowMemorySet.java b/api/src/main/java/io/github/waterfallmc/waterfall/utils/LowMemorySet.java
|
||||||
new file mode 100644
|
new file mode 100644
|
||||||
index 0000000..c62e3d4
|
index 0000000..a1b6981
|
||||||
--- /dev/null
|
--- /dev/null
|
||||||
+++ b/api/src/main/java/io/github/waterfallmc/waterfall/utils/LowMemorySet.java
|
+++ b/api/src/main/java/io/github/waterfallmc/waterfall/utils/LowMemorySet.java
|
||||||
@@ -0,0 +1,176 @@
|
@@ -0,0 +1,151 @@
|
||||||
+package io.github.waterfallmc.waterfall.utils;
|
+package io.github.waterfallmc.waterfall.utils;
|
||||||
+
|
+
|
||||||
+import lombok.*;
|
|
||||||
+
|
|
||||||
+import java.util.AbstractSet;
|
+import java.util.AbstractSet;
|
||||||
+import java.util.ArrayList;
|
+import java.util.ArrayList;
|
||||||
+import java.util.Collection;
|
+import java.util.Collection;
|
||||||
@ -39,13 +37,10 @@ index 0000000..c62e3d4
|
|||||||
+ */
|
+ */
|
||||||
+public class LowMemorySet<T extends Comparable<T>> extends AbstractSet<T> implements Set<T> {
|
+public class LowMemorySet<T extends Comparable<T>> extends AbstractSet<T> implements Set<T> {
|
||||||
+ private final List<T> backing;
|
+ private final List<T> backing;
|
||||||
+ @Setter
|
|
||||||
+ private boolean trimAggressively;
|
|
||||||
+
|
+
|
||||||
+ protected LowMemorySet(List<T> list) {
|
+ private LowMemorySet(List<T> list) {
|
||||||
+ this.backing = checkNotNull(list, "Null list");
|
+ this.backing = checkNotNull(list, "Null list");
|
||||||
+ this.sort(); // We have to sort any initial elements
|
+ this.sort(); // We have to sort any initial elements
|
||||||
+ this.trim(true);
|
|
||||||
+ }
|
+ }
|
||||||
+
|
+
|
||||||
+ public static <T extends Comparable<T>> LowMemorySet<T> create() {
|
+ public static <T extends Comparable<T>> LowMemorySet<T> create() {
|
||||||
@ -63,15 +58,6 @@ index 0000000..c62e3d4
|
|||||||
+
|
+
|
||||||
+ private void sort() {
|
+ private void sort() {
|
||||||
+ backing.sort(null);
|
+ backing.sort(null);
|
||||||
+ this.trim();
|
|
||||||
+ }
|
|
||||||
+
|
|
||||||
+ private void trim() {
|
|
||||||
+ trim(false);
|
|
||||||
+ }
|
|
||||||
+
|
|
||||||
+ private void trim(boolean force) {
|
|
||||||
+ if (backing instanceof ArrayList && force || trimAggressively) ((ArrayList<T>) backing).trimToSize();
|
|
||||||
+ }
|
+ }
|
||||||
+
|
+
|
||||||
+ @Override
|
+ @Override
|
||||||
@ -133,25 +119,18 @@ index 0000000..c62e3d4
|
|||||||
+ int index = indexOf(o);
|
+ int index = indexOf(o);
|
||||||
+ if (index < 0) return false;
|
+ if (index < 0) return false;
|
||||||
+ T old = backing.remove(index);
|
+ T old = backing.remove(index);
|
||||||
+ this.trim();
|
|
||||||
+ assert old == o;
|
+ assert old == o;
|
||||||
+ return old != null;
|
+ return old != null;
|
||||||
+ }
|
+ }
|
||||||
+
|
+
|
||||||
+ @Override
|
+ @Override
|
||||||
+ public boolean removeAll(Collection<?> c) {
|
+ public boolean removeAll(Collection<?> c) {
|
||||||
+ int oldSize = this.size();
|
+ return backing.removeIf(c::contains);
|
||||||
+ boolean result = backing.removeIf(c::contains);
|
|
||||||
+ this.trim(oldSize - this.size() > 10);
|
|
||||||
+ return result;
|
|
||||||
+ }
|
+ }
|
||||||
+
|
+
|
||||||
+ @Override
|
+ @Override
|
||||||
+ public boolean retainAll(Collection<?> c) {
|
+ public boolean retainAll(Collection<?> c) {
|
||||||
+ int oldSize = this.size();
|
+ return backing.removeIf((o) -> !c.contains(o));
|
||||||
+ boolean result = backing.removeIf((o) -> !c.contains(o));
|
|
||||||
+ this.trim(oldSize - this.size() > 10);
|
|
||||||
+ return result;
|
|
||||||
+ }
|
+ }
|
||||||
+
|
+
|
||||||
+ @Override
|
+ @Override
|
||||||
@ -165,7 +144,6 @@ index 0000000..c62e3d4
|
|||||||
+ @Override
|
+ @Override
|
||||||
+ public void clear() {
|
+ public void clear() {
|
||||||
+ backing.clear();
|
+ backing.clear();
|
||||||
+ this.trim(true);
|
|
||||||
+ }
|
+ }
|
||||||
+
|
+
|
||||||
+ @Override
|
+ @Override
|
||||||
@ -185,10 +163,7 @@ index 0000000..c62e3d4
|
|||||||
+
|
+
|
||||||
+ @Override
|
+ @Override
|
||||||
+ public boolean removeIf(Predicate<? super T> filter) {
|
+ public boolean removeIf(Predicate<? super T> filter) {
|
||||||
+ int oldSize = this.size();
|
+ return backing.removeIf(filter);
|
||||||
+ boolean worked = backing.removeIf(filter);
|
|
||||||
+ this.trim(this.size() - oldSize > 10);
|
|
||||||
+ return worked;
|
|
||||||
+ }
|
+ }
|
||||||
+}
|
+}
|
||||||
diff --git a/api/src/main/java/net/md_5/bungee/api/score/Team.java b/api/src/main/java/net/md_5/bungee/api/score/Team.java
|
diff --git a/api/src/main/java/net/md_5/bungee/api/score/Team.java b/api/src/main/java/net/md_5/bungee/api/score/Team.java
|
||||||
@ -292,5 +267,5 @@ index 0000000..5aa306a
|
|||||||
+
|
+
|
||||||
+}
|
+}
|
||||||
--
|
--
|
||||||
2.10.0
|
2.7.4
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user