Replace LinkedList with ArrayList in a lot of places
This commit is contained in:
parent
e66a6035df
commit
04c9d8ddfe
@ -619,7 +619,7 @@ class AndroidResearchType(
|
||||
var iconText: Component? = null,
|
||||
) {
|
||||
private val items = ArrayList<Pair<Ingredient, Int>>()
|
||||
private val prerequisites = LinkedList<Reference>()
|
||||
private val prerequisites = ArrayList<Reference>()
|
||||
private val blockers = ArrayList<Reference>()
|
||||
|
||||
private val features = ArrayList<FeatureReference>()
|
||||
|
@ -105,8 +105,16 @@ abstract class MatteryWorkerBlockEntity<JobType : MatteryWorkerBlockEntity.Job>(
|
||||
var throttleTicks = 0
|
||||
protected set
|
||||
|
||||
protected open fun jobUpdated(oldJob: JobType?, newJob: JobType?) {}
|
||||
|
||||
var currentJob: JobType? = null
|
||||
protected set
|
||||
protected set(value) {
|
||||
if (field != value) {
|
||||
val old = field
|
||||
field = value
|
||||
jobUpdated(old, value)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Can be whatever you want, but [IdleReason] certainly contains all cases
|
||||
|
@ -34,8 +34,8 @@ import java.util.LinkedList
|
||||
import java.util.WeakHashMap
|
||||
|
||||
private data class Subscribers(
|
||||
val blockEntities: LinkedList<WeakReference<SynchronizedBlockEntity>> = LinkedList(),
|
||||
val players: LinkedList<ServerPlayer> = LinkedList(),
|
||||
val blockEntities: ArrayList<WeakReference<SynchronizedBlockEntity>> = ArrayList(0),
|
||||
val players: ArrayList<ServerPlayer> = ArrayList(1),
|
||||
val level: WeakReference<Level>,
|
||||
val chunkPos: Long,
|
||||
var changeset: Int = 0
|
||||
|
@ -1,15 +1,14 @@
|
||||
package ru.dbotthepony.mc.otm.core
|
||||
|
||||
import org.apache.logging.log4j.LogManager
|
||||
import java.util.*
|
||||
import kotlin.ConcurrentModificationException
|
||||
|
||||
class TickList {
|
||||
private val conditional = LinkedList<IConditionalTickable>()
|
||||
private val once = LinkedList<ITickable>()
|
||||
private val conditional = ArrayDeque<IConditionalTickable>()
|
||||
private val once = ArrayDeque<ITickable>()
|
||||
|
||||
private val conditionalValveTime = LinkedList<IConditionalTickable>()
|
||||
private val onceValveTime = LinkedList<ITickable>()
|
||||
private val conditionalValveTime = ArrayList<IConditionalTickable>()
|
||||
private val onceValveTime = ArrayList<ITickable>()
|
||||
|
||||
private var inTicker = false
|
||||
|
||||
|
@ -1,10 +1,8 @@
|
||||
package ru.dbotthepony.mc.otm.core
|
||||
|
||||
import java.util.LinkedList
|
||||
|
||||
class TimerQueue {
|
||||
private var ticks = 0
|
||||
private val list = LinkedList<Timer>()
|
||||
private val list = ArrayDeque<Timer>()
|
||||
|
||||
inner class Timer(val timerTicks: Int, val runnable: Runnable) {
|
||||
val ringAt = ticks + timerTicks
|
||||
@ -54,7 +52,7 @@ class TimerQueue {
|
||||
ticks++
|
||||
|
||||
while (list.isNotEmpty()) {
|
||||
val head = list.first
|
||||
val head = list.first()
|
||||
|
||||
if (head.ringAt <= ticks) {
|
||||
head.execute()
|
||||
|
@ -3,6 +3,7 @@ package ru.dbotthepony.mc.otm.network
|
||||
import it.unimi.dsi.fastutil.io.FastByteArrayOutputStream
|
||||
import it.unimi.dsi.fastutil.objects.Reference2ObjectFunction
|
||||
import it.unimi.dsi.fastutil.objects.Reference2ObjectOpenHashMap
|
||||
import it.unimi.dsi.fastutil.objects.ReferenceArraySet
|
||||
import net.minecraft.world.item.ItemStack
|
||||
import ru.dbotthepony.mc.otm.core.*
|
||||
import java.io.DataInputStream
|
||||
@ -73,8 +74,8 @@ class FieldSynchronizer(private val callback: Runnable, private val alwaysCallCa
|
||||
constructor() : this(Runnable {}, false)
|
||||
constructor(callback: Runnable) : this(callback, false)
|
||||
|
||||
private val fields = ArrayList<IField<*>>()
|
||||
private val observers = LinkedList<IField<*>>()
|
||||
private val fields = ArrayList<IField<*>>(0)
|
||||
private val observers = ArrayList<IField<*>>(0)
|
||||
|
||||
val isEmpty: Boolean get() = fields.isEmpty()
|
||||
val isNotEmpty: Boolean get() = fields.isNotEmpty()
|
||||
@ -241,7 +242,7 @@ class FieldSynchronizer(private val callback: Runnable, private val alwaysCallCa
|
||||
)
|
||||
}
|
||||
|
||||
private val endpoints = LinkedList<WeakReference<Endpoint>>()
|
||||
private val endpoints = ArrayList<WeakReference<Endpoint>>()
|
||||
val defaultEndpoint = Endpoint()
|
||||
|
||||
private var lastEndpointsCleanup = System.nanoTime()
|
||||
@ -274,7 +275,7 @@ class FieldSynchronizer(private val callback: Runnable, private val alwaysCallCa
|
||||
|
||||
inner class Endpoint {
|
||||
init {
|
||||
endpoints.addLast(WeakReference(this))
|
||||
endpoints.add(WeakReference(this))
|
||||
|
||||
if (System.nanoTime() - lastEndpointsCleanup >= 60_000_000_000) {
|
||||
lastEndpointsCleanup = System.nanoTime()
|
||||
@ -291,7 +292,9 @@ class FieldSynchronizer(private val callback: Runnable, private val alwaysCallCa
|
||||
}
|
||||
}
|
||||
|
||||
private val dirtyFields = LinkedList<IField<*>>()
|
||||
private val dirtyFields = ReferenceArraySet<IField<*>>(0)
|
||||
|
||||
// use LinkedList because it is ensured memory is freed on LinkedList#clear
|
||||
private val mapBacklogs = Reference2ObjectOpenHashMap<Map<*, *>, LinkedList<Pair<Any?, (DataOutputStream) -> Unit>>>()
|
||||
|
||||
var unused: Boolean = false
|
||||
@ -324,9 +327,7 @@ class FieldSynchronizer(private val callback: Runnable, private val alwaysCallCa
|
||||
return
|
||||
}
|
||||
|
||||
if (field !in dirtyFields) {
|
||||
dirtyFields.addLast(field)
|
||||
}
|
||||
dirtyFields.add(field)
|
||||
}
|
||||
|
||||
internal fun <K, V> getMapBacklog(map: Map<K, V>): LinkedList<Pair<Any?, (DataOutputStream) -> Unit>> {
|
||||
|
Loading…
Reference in New Issue
Block a user