Remove Decimal interning
This commit is contained in:
parent
9276d087df
commit
849563e7eb
@ -128,7 +128,7 @@ class Decimal private constructor(val mag: BigInteger, marker: Nothing?) : Numbe
|
||||
return this
|
||||
}
|
||||
|
||||
return Decimal(mag + other.mag, null).interned()
|
||||
return Decimal(mag + other.mag, null)
|
||||
}
|
||||
|
||||
operator fun minus(other: Decimal): Decimal {
|
||||
@ -136,7 +136,7 @@ class Decimal private constructor(val mag: BigInteger, marker: Nothing?) : Numbe
|
||||
return this
|
||||
}
|
||||
|
||||
return Decimal(mag - other.mag, null).interned()
|
||||
return Decimal(mag - other.mag, null)
|
||||
}
|
||||
|
||||
operator fun times(other: Decimal): Decimal {
|
||||
@ -145,16 +145,16 @@ class Decimal private constructor(val mag: BigInteger, marker: Nothing?) : Numbe
|
||||
} else if (other.mag == BigInteger.ONE) {
|
||||
return this
|
||||
} else if (other.mag == BI_MINUS_ONE) {
|
||||
return Decimal(-mag, null).interned()
|
||||
return Decimal(-mag, null)
|
||||
}
|
||||
|
||||
val result = mag * other.mag
|
||||
val (a, b) = result.divideAndRemainder(PRECISION_POW_BI)
|
||||
|
||||
if (b >= PRECISION_POW_BI_HIGH) {
|
||||
return Decimal(a + BigInteger.ONE, null).interned()
|
||||
return Decimal(a + BigInteger.ONE, null)
|
||||
} else {
|
||||
return Decimal(a, null).interned()
|
||||
return Decimal(a, null)
|
||||
}
|
||||
}
|
||||
|
||||
@ -164,10 +164,10 @@ class Decimal private constructor(val mag: BigInteger, marker: Nothing?) : Numbe
|
||||
} else if (other.mag == BigInteger.ONE) {
|
||||
return this
|
||||
} else if (other.mag == BI_MINUS_ONE) {
|
||||
return Decimal(-mag, null).interned()
|
||||
return Decimal(-mag, null)
|
||||
}
|
||||
|
||||
return Decimal((mag * PRECISION_POW_BI) / other.mag, null).interned()
|
||||
return Decimal((mag * PRECISION_POW_BI) / other.mag, null)
|
||||
}
|
||||
|
||||
operator fun rem(other: Decimal): Decimal {
|
||||
@ -413,7 +413,7 @@ class Decimal private constructor(val mag: BigInteger, marker: Nothing?) : Numbe
|
||||
return this
|
||||
}
|
||||
|
||||
return Decimal(-mag, null).interned()
|
||||
return Decimal(-mag, null)
|
||||
}
|
||||
|
||||
operator fun unaryPlus() = this
|
||||
@ -578,10 +578,6 @@ class Decimal private constructor(val mag: BigInteger, marker: Nothing?) : Numbe
|
||||
return toBigDecmial().divide(divisor.toBigDecmial(), PERCENTAGE_CONTEXT).toFloat()
|
||||
}
|
||||
|
||||
private fun interned(): Decimal {
|
||||
return pool[this] ?: this
|
||||
}
|
||||
|
||||
@Suppress("unused")
|
||||
companion object {
|
||||
/**
|
||||
@ -604,13 +600,6 @@ class Decimal private constructor(val mag: BigInteger, marker: Nothing?) : Numbe
|
||||
private const val cacheSizeL = cacheSize.toLong()
|
||||
|
||||
private val cache = Array(cacheSize) { Decimal(BigInteger.valueOf(it.toLong() - cacheSize / 2)) }
|
||||
private val pool = Object2ObjectOpenHashMap<Decimal, Decimal>()
|
||||
|
||||
init {
|
||||
for (value in cache) {
|
||||
pool[value] = value
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns pooled value if present, otherwise constructs new object
|
||||
@ -648,11 +637,11 @@ class Decimal private constructor(val mag: BigInteger, marker: Nothing?) : Numbe
|
||||
@JvmStatic
|
||||
fun valueOf(value: Byte) = valueOf(value.toInt())
|
||||
|
||||
@JvmStatic fun valueOf(value: BigInteger) = Decimal(value).interned()
|
||||
@JvmStatic fun valueOf(value: BigDecimal) = Decimal(value).interned()
|
||||
@JvmStatic fun valueOf(value: String) = Decimal(value).interned()
|
||||
@JvmStatic fun valueOf(value: Float) = Decimal(value).interned()
|
||||
@JvmStatic fun valueOf(value: Double) = Decimal(value).interned()
|
||||
@JvmStatic fun valueOf(value: BigInteger) = Decimal(value)
|
||||
@JvmStatic fun valueOf(value: BigDecimal) = Decimal(value)
|
||||
@JvmStatic fun valueOf(value: String) = Decimal(value)
|
||||
@JvmStatic fun valueOf(value: Float) = Decimal(value)
|
||||
@JvmStatic fun valueOf(value: Double) = Decimal(value)
|
||||
|
||||
@JvmStatic
|
||||
fun fromByteArray(input: ByteArray): Decimal {
|
||||
|
Loading…
Reference in New Issue
Block a user