Skip to content

Commit

Permalink
Merge pull request #235 from TimWSpence/optimize-eval-with-switch
Browse files Browse the repository at this point in the history
Optimization - bind evaluation using @switch
  • Loading branch information
TimWSpence authored Dec 14, 2020
2 parents 30aa851 + b86d0e0 commit 3bf24d1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,19 @@
* limitations under the License.
*/

package io.github.timwspence.cats.stm
package io.github.timwspence.cats.stm;

private[stm] object STMConstants {
final class STMConstants
{

type T = Byte
val PureT: T = 0
val AllocT: T = 1
val BindT: T = 2
val HandleErrorT: T = 3
val GetT: T = 4
val ModifyT: T = 5
val OrElseT: T = 6
val AbortT: T = 7
val RetryT: T = 8
public static final byte PureT = 0;
public static final byte AllocT = 1;
public static final byte BindT = 2;
public static final byte HandleErrorT = 3;
public static final byte GetT = 4;
public static final byte ModifyT = 5;
public static final byte OrElseT = 6;
public static final byte AbortT = 7;
public static final byte RetryT = 8;

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

package io.github.timwspence.cats.stm

import scala.annotation.tailrec
import scala.annotation.{switch, tailrec}
import scala.reflect.ClassTag

import cats.data.EitherT
Expand Down Expand Up @@ -434,6 +434,7 @@ trait STMLike[F[_]] {
private[stm] case object TRetry extends TResult[Nothing]

private[stm] type TVarId = Long
private[stm] type T = Byte

private[stm] case class TLog(private var map: Map[TVarId, TLogEntry]) {

Expand Down Expand Up @@ -564,7 +565,7 @@ trait STMLike[F[_]] {
case class Eff(run: F[Txn[Any]]) extends Trampoline

type Cont = Any => Txn[Any]
type Tag = Int
type Tag = Byte
val cont: Tag = 0
val handle: Tag = 1

Expand All @@ -583,7 +584,7 @@ trait STMLike[F[_]] {
ref: Ref[F, List[Deferred[F, Unit]]],
txn: Txn[Any]
): Trampoline =
txn.tag match {
(txn.tag: @switch) match {
case PureT =>
val t = txn.asInstanceOf[Pure[Any]]
while (!tags.isEmpty && !(tags.head == cont)) {
Expand Down

0 comments on commit 3bf24d1

Please sign in to comment.