You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Nov 29, 2020. It is now read-only.
implicitdefeqList[A](implicitA:Eq[A]):Eq[List[A]] =newEq[A] { ... }
implicitclassEqOps[A](value: A) {
def===(other: A)(implicitA:Eq[A]):Boolean=A.equal(value, other)
}
...
objectTest {
deftest:Unit= {
vala:List[Int] = ...
valb:List[Int] = ...
for (i <0 until 100) {
a === b
}
}
}
The body of the loop will compile to:
newEqOps(a).===(b)(eqList(eqInt))
So there are two allocations per comparison, one allocation of the syntax extension class and one for the instance of Eq[List[A]]. This optimization should fix the latter by instantiating the instance in the outermost static scope,
objectTest {
implicitval$ev1:Eq[List[A]] = eqList(eqInt)
deftest:Unit= {
vala:List[Int] = ...
valb:List[Int] = ...
for (i <0 until 100) {
newEqOps(a).===(b)($ev1)
}
}
}
or at the beginning of the function:
classTest {
deftest:Unit= {
implicitval$ev1:Eq[List[A]] = eqList(eqInt)
vala:List[Int] = ...
valb:List[Int] = ...
for (i <0 until 100) {
newEqOps(a).===(b)($ev1)
}
}
}