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