Cache values() array in enums

Signed-off-by: Graham <gpe@openrs2.dev>
bzip2
Graham 4 years ago
parent a4234d066d
commit b51b2f5e77
  1. 3
      cache/src/main/java/dev/openrs2/cache/Js5CompressionType.kt
  2. 2
      cache/src/main/java/dev/openrs2/cache/Js5Protocol.kt

@ -40,8 +40,9 @@ public enum class Js5CompressionType {
} }
public companion object { public companion object {
private val values = values()
public fun fromOrdinal(ordinal: Int): Js5CompressionType? { public fun fromOrdinal(ordinal: Int): Js5CompressionType? {
val values = values()
return if (ordinal >= 0 && ordinal < values.size) { return if (ordinal >= 0 && ordinal < values.size) {
values[ordinal] values[ordinal]
} else { } else {

@ -10,10 +10,10 @@ public enum class Js5Protocol {
public companion object { public companion object {
private const val OFFSET = 5 private const val OFFSET = 5
private val values = values()
public fun fromId(id: Int): Js5Protocol? { public fun fromId(id: Int): Js5Protocol? {
val ordinal = id - OFFSET val ordinal = id - OFFSET
val values = values()
return if (ordinal >= 0 && ordinal < values.size) { return if (ordinal >= 0 && ordinal < values.size) {
values[ordinal] values[ordinal]
} else { } else {

Loading…
Cancel
Save