From 8c32a2cd7a7de292a5ac9da363cd7c2a3cdb9600 Mon Sep 17 00:00:00 2001 From: DBotThePony Date: Fri, 14 Apr 2023 23:58:17 +0700 Subject: [PATCH] Put constants in decimal cache --- .../kotlin/ru/dbotthepony/mc/otm/core/math/Decimal.kt | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/core/math/Decimal.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/core/math/Decimal.kt index 3332158ed..a200f1ff9 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/core/math/Decimal.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/core/math/Decimal.kt @@ -746,6 +746,14 @@ class Decimal @JvmOverloads constructor(whole: BigInteger, decimal: Double = 0.0 private val cache = Array(2048) { Decimal(it - 1024, 0.0) } + init { + cache[1024] = ZERO + cache[1025] = ONE + cache[1023] = MINUS_ONE + cache[1026] = TWO + cache[1034] = TEN + } + /** * Returns pooled value if present, otherwise constructs new object */