PaperMC/patches/unapplied/server/0405-Remove-streams-from-PairedQueue.patch
2021-11-30 19:26:33 +01:00

46 lines
2 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Spottedleaf <spottedleaf@spottedleaf.dev>
Date: Mon, 6 Apr 2020 18:10:43 -0700
Subject: [PATCH] Remove streams from PairedQueue
We shouldn't be doing stream calls just to see if the queue is
empty. This creates loads of garbage thanks to how often it's called.
diff --git a/src/main/java/net/minecraft/util/thread/StrictQueue.java b/src/main/java/net/minecraft/util/thread/StrictQueue.java
index 66591e23bc9e0df968fb6b291a3ad3773debdf29..c4a20df21e1fe5556fddac64b52d542579758e2c 100644
--- a/src/main/java/net/minecraft/util/thread/StrictQueue.java
+++ b/src/main/java/net/minecraft/util/thread/StrictQueue.java
@@ -22,9 +22,12 @@ public interface StrictQueue<T, F> {
private final List<Queue<Runnable>> queueList;
public FixedPriorityQueue(int priorityCount) {
- this.queueList = IntStream.range(0, priorityCount).mapToObj((i) -> {
- return Queues.newConcurrentLinkedQueue();
- }).collect(Collectors.toList());
+ // Paper start - remove streams
+ this.queueList = new java.util.ArrayList<>(priorityCount); // queues
+ for (int j = 0; j < priorityCount; ++j) {
+ this.queueList.add(Queues.newConcurrentLinkedQueue());
+ }
+ // Paper end - remove streams
}
@Nullable
@@ -49,7 +52,16 @@ public interface StrictQueue<T, F> {
@Override
public boolean isEmpty() {
- return this.queueList.stream().allMatch(Collection::isEmpty);
+ // Paper start - remove streams
+ // why are we doing streams every time we might want to execute a task?
+ for (int i = 0, len = this.queueList.size(); i < len; ++i) {
+ Queue<Runnable> queue = this.queueList.get(i);
+ if (!queue.isEmpty()) {
+ return false;
+ }
+ }
+ return true;
+ // Paper end - remove streams
}
@Override