Skip to content

Commit b214211

Browse files
authored
Merge pull request scala/scala#8883 from mkeskells/2.12.x_fasterRedBlackEqual
faster equality checks for RedBlackTree - followup
2 parents 3ead93a + bd652e8 commit b214211

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

library/src/scala/collection/immutable/RedBlackTree.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -355,16 +355,16 @@ private[collection] object RedBlackTree {
355355
else if (tree.left eq null) tree
356356
else findLeftMostOrPopOnEmpty(goLeft(tree))
357357

358-
private[this] def pushNext(tree: Tree[A, B]): Unit = {
358+
@`inline` private[this] def pushNext(tree: Tree[A, B]): Unit = {
359359
stackOfNexts(index) = tree
360360
index += 1
361361
}
362-
protected final def popNext(): Tree[A, B] = if (index == 0) null else {
362+
@`inline` protected final def popNext(): Tree[A, B] = if (index == 0) null else {
363363
index -= 1
364364
stackOfNexts(index)
365365
}
366366

367-
private[this] var stackOfNexts = if (root eq null) null else {
367+
protected[this] val stackOfNexts = if (root eq null) null else {
368368
/*
369369
* According to "Ralf Hinze. Constructing red-black trees" [http://www.cs.ox.ac.uk/ralf.hinze/publications/#P5]
370370
* the maximum height of a red-black tree is 2*log_2(n + 2) - 2.
@@ -378,7 +378,7 @@ private[collection] object RedBlackTree {
378378
new Array[Tree[A, B]](maximumHeight)
379379
}
380380
private[this] var index = 0
381-
protected var lookahead: Tree[A, B] = start map startFrom getOrElse findLeftMostOrPopOnEmpty(root)
381+
protected var lookahead: Tree[A, B] = if (start isDefined) startFrom(start.get) else findLeftMostOrPopOnEmpty(root)
382382

383383
/**
384384
* Find the leftmost subtree whose key is equal to the given key, or if no such thing,

0 commit comments

Comments
 (0)