Skip to content

Commit ee50542

Browse files
committed
Microoptimization in List.equals
1 parent 11bfb26 commit ee50542

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/library/scala/collection/immutable/List.scala

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -526,11 +526,13 @@ sealed abstract class List[+A]
526526
override def equals(o: scala.Any): Boolean = {
527527
@tailrec def listEq(a: List[_], b: List[_]): Boolean =
528528
(a eq b) || {
529-
if (a.nonEmpty && b.nonEmpty && a.head == b.head) {
529+
val aEmpty = a.isEmpty
530+
val bEmpty = b.isEmpty
531+
if (!(aEmpty || bEmpty) && a.head == b.head) {
530532
listEq(a.tail, b.tail)
531533
}
532534
else {
533-
a.isEmpty && b.isEmpty
535+
aEmpty && bEmpty
534536
}
535537
}
536538

0 commit comments

Comments
 (0)