Use faster compare methods
The static compare methods are significantly faster than scala's Rich<Prim> compare methods, and they are equivalent speed to subtraction but handle edge cases correctly.pull/5147/head
parent
ee1079139c
commit
fd42b54e16
|
@ -5,7 +5,7 @@ case class ApiVersion(value: Int) extends AnyVal with IntValue with Ordered[ApiV
|
|||
def v2 = value == 2
|
||||
def v3 = value == 3
|
||||
def v4 = value == 4
|
||||
def compare(other: ApiVersion) = value compare other.value
|
||||
def compare(other: ApiVersion) = Integer.compare(value, other.value)
|
||||
def gt(other: Int) = value > other
|
||||
def gte(other: Int) = value >= other
|
||||
}
|
||||
|
|
|
@ -27,8 +27,8 @@ object Usd {
|
|||
def apply(value: Int): Usd = Usd(BigDecimal(value))
|
||||
}
|
||||
case class Cents(value: Int) extends AnyVal with Ordered[Cents] {
|
||||
def compare(other: Cents) = value compare other.value
|
||||
def usd = Usd(value / 100d)
|
||||
def compare(other: Cents) = Integer.compare(value, other.value)
|
||||
def usd = Usd(BigDecimal(value, 2))
|
||||
override def toString = usd.toString
|
||||
}
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@ object Socket extends Socket {
|
|||
case class Uids(uids: Set[Uid])
|
||||
|
||||
case class SocketVersion(value: Int) extends AnyVal with IntValue with Ordered[SocketVersion] {
|
||||
def compare(other: SocketVersion) = value compare other.value
|
||||
def compare(other: SocketVersion) = Integer.compare(value, other.value)
|
||||
def inc = SocketVersion(value + 1)
|
||||
}
|
||||
|
||||
|
|
|
@ -151,7 +151,7 @@ object Chapter {
|
|||
case class IdName(id: Id, name: Name)
|
||||
|
||||
case class Ply(value: Int) extends AnyVal with Ordered[Ply] {
|
||||
def compare(that: Ply) = value - that.value
|
||||
def compare(that: Ply) = Integer.compare(value, that.value)
|
||||
}
|
||||
|
||||
def defaultName(order: Int) = Name(s"Chapter $order")
|
||||
|
|
|
@ -56,7 +56,7 @@ object Eval {
|
|||
def invert = Cp(value = -value)
|
||||
def invertIf(cond: Boolean) = if (cond) invert else this
|
||||
|
||||
def compare(other: Cp) = value compare other.value
|
||||
def compare(other: Cp) = Integer.compare(value, other.value)
|
||||
|
||||
def signum: Int = Math.signum(value).toInt
|
||||
}
|
||||
|
@ -75,7 +75,7 @@ object Eval {
|
|||
def invert = Mate(value = -value)
|
||||
def invertIf(cond: Boolean) = if (cond) invert else this
|
||||
|
||||
def compare(other: Mate) = value compare other.value
|
||||
def compare(other: Mate) = Integer.compare(value, other.value)
|
||||
|
||||
def signum: Int = Math.signum(value).toInt
|
||||
|
||||
|
|
Loading…
Reference in New Issue