Skip to content

Commit

Permalink
[core] avoid AnyVal (#803)
Browse files Browse the repository at this point in the history
Following up on
#800 (comment). Since
Scala 3 doesn't have specialization `AnyVal` values can keep boxing on
every transformation.
  • Loading branch information
fwbrasil authored Oct 31, 2024
1 parent 84c0f9d commit db25f66
Show file tree
Hide file tree
Showing 8 changed files with 13 additions and 13 deletions.
4 changes: 2 additions & 2 deletions kyo-core/shared/src/main/scala/kyo/Adder.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import java.util.concurrent.atomic as j

/** A wrapper for Java's LongAdder.
*/
final case class LongAdder private (unsafe: LongAdder.Unsafe) extends AnyVal:
final case class LongAdder private (unsafe: LongAdder.Unsafe):

/** Adds the given value to the sum.
*
Expand Down Expand Up @@ -83,7 +83,7 @@ end LongAdder

/** A wrapper for Java's DoubleAdde
*/
final case class DoubleAdder private (unsafe: DoubleAdder.Unsafe) extends AnyVal:
final case class DoubleAdder private (unsafe: DoubleAdder.Unsafe):

/** Adds the given value to the sum.
*
Expand Down
8 changes: 4 additions & 4 deletions kyo-core/shared/src/main/scala/kyo/Atomic.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import java.util.concurrent.atomic as j

/** A wrapper for Java's AtomicInteger.
*/
final case class AtomicInt private (unsafe: AtomicInt.Unsafe) extends AnyVal:
final case class AtomicInt private (unsafe: AtomicInt.Unsafe):

/** Gets the current value.
* @return
Expand Down Expand Up @@ -127,7 +127,7 @@ end AtomicInt

/** A wrapper for Java's AtomicLong.
*/
final case class AtomicLong private (unsafe: AtomicLong.Unsafe) extends AnyVal:
final case class AtomicLong private (unsafe: AtomicLong.Unsafe):
/** Gets the current value.
* @return
* The current long value
Expand Down Expand Up @@ -250,7 +250,7 @@ end AtomicLong

/** A wrapper for Java's AtomicBoolean.
*/
final case class AtomicBoolean private (unsafe: AtomicBoolean.Unsafe) extends AnyVal:
final case class AtomicBoolean private (unsafe: AtomicBoolean.Unsafe):
/** Gets the current value.
* @return
* The current boolean value
Expand Down Expand Up @@ -330,7 +330,7 @@ end AtomicBoolean
* @tparam A
* The type of the referenced value
*/
final case class AtomicRef[A] private (unsafe: AtomicRef.Unsafe[A]) extends AnyVal:
final case class AtomicRef[A] private (unsafe: AtomicRef.Unsafe[A]):

/** Gets the current value.
* @return
Expand Down
2 changes: 1 addition & 1 deletion kyo-core/shared/src/main/scala/kyo/Barrier.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import scala.annotation.tailrec
* - The barrier releases all waiting parties when the last party arrives.
* - The barrier can only be used once. After all parties have been released, the barrier cannot be reset.
*/
final case class Barrier private (unsafe: Barrier.Unsafe) extends AnyVal:
final case class Barrier private (unsafe: Barrier.Unsafe):

/** Waits for the barrier to be released.
*
Expand Down
4 changes: 2 additions & 2 deletions kyo-core/shared/src/main/scala/kyo/Clock.scala
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ end Clock
object Clock:

/** A stopwatch for measuring elapsed time. */
final case class Stopwatch private[Clock] (unsafe: Stopwatch.Unsafe) extends AnyVal:
final case class Stopwatch private[Clock] (unsafe: Stopwatch.Unsafe):
/** Gets the elapsed time since the stopwatch was created.
*
* @return
Expand All @@ -70,7 +70,7 @@ object Clock:
end Stopwatch

/** A deadline for checking remaining time or if it's overdue. */
final case class Deadline private[Clock] (unsafe: Deadline.Unsafe) extends AnyVal:
final case class Deadline private[Clock] (unsafe: Deadline.Unsafe):
/** Gets the time left until the deadline.
*
* @return
Expand Down
2 changes: 1 addition & 1 deletion kyo-core/shared/src/main/scala/kyo/Console.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import java.io.IOException

/** Represents a console for input and output operations.
*/
final case class Console(unsafe: Console.Unsafe) extends AnyVal:
final case class Console(unsafe: Console.Unsafe):

/** Reads a line from the console.
*
Expand Down
2 changes: 1 addition & 1 deletion kyo-core/shared/src/main/scala/kyo/Latch.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import scala.annotation.tailrec
*
* A `Latch` is initialized with a count and can be awaited. It is released by calling `release` the specified number of times.
*/
final case class Latch private (unsafe: Latch.Unsafe) extends AnyVal:
final case class Latch private (unsafe: Latch.Unsafe):

/** Waits until the latch has counted down to zero.
*
Expand Down
2 changes: 1 addition & 1 deletion kyo-core/shared/src/main/scala/kyo/Stat.scala
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ abstract class CounterGauge:
def collect(using Frame): Long < IO
end CounterGauge

final class Stat(private val registryScope: StatsRegistry.Scope) extends AnyVal:
final class Stat(private val registryScope: StatsRegistry.Scope):

/** Create a new Stat instance with an additional scope.
* @param path
Expand Down
2 changes: 1 addition & 1 deletion kyo-core/shared/src/main/scala/kyo/stats/attributes.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package kyo.stats
import kyo.stats.Attributes.AsAttribute
import scala.annotation.implicitNotFound

case class Attributes(get: List[Attributes.Attribute]) extends AnyVal:
case class Attributes(get: List[Attributes.Attribute]):
def add(a: Attributes): Attributes =
Attributes(get ++ a.get)
def add[A](name: String, value: A)(implicit a: AsAttribute[A]): Attributes =
Expand Down

0 comments on commit db25f66

Please sign in to comment.