Skip to content

Commit

Permalink
fix: Fixed incorrect sorting in EventBus
Browse files Browse the repository at this point in the history
[warn] The performance of it is bad
  • Loading branch information
slmpc committed Jan 18, 2025
1 parent 2c75c4b commit f836655
Showing 1 changed file with 2 additions and 10 deletions.
12 changes: 2 additions & 10 deletions src/main/kotlin/dev/exceptionteam/sakura/events/EventBus.kt
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,9 @@ object EventBus {
@Suppress("UNCHECKED_CAST")
@JvmStatic
fun subscribe(listener: EventListener<*>) {
for (i in listeners.indices) {
val other = listeners[i]
if (listener == other) {
return
} else if (listener.priority > other.priority) {
listeners.add(i, listener as EventListener<Any>)
return
}
}

// The performance of this method is bad
listeners.add(listener as EventListener<Any>)
listeners.sortByDescending { it.priority }
}

@JvmStatic
Expand Down

0 comments on commit f836655

Please sign in to comment.