Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimization - bind evaluation using @switch #235

Merged
merged 1 commit into from
Dec 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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