Skip to content

Commit

Permalink
Improved performance of RedBlack.NonEmpty.nth (helps take/drop/split/…
Browse files Browse the repository at this point in the history
…etc).
  • Loading branch information
erikrozendaal committed Dec 28, 2011
1 parent b421bba commit 4a0c4bb
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/library/scala/collection/immutable/RedBlack.scala
Expand Up @@ -262,8 +262,9 @@ object RedBlack {
def last = if (right eq Empty.Instance) key else right.last
val count = 1 + left.count + right.count
protected[immutable] def nth(n: Int) = {
if (n < left.count) left.nth(n)
else if (n > left.count) right.nth(n - left.count - 1)
val count = left.count
if (n < count) left.nth(n)
else if (n > count) right.nth(n - count - 1)
else this
}
}
Expand Down

0 comments on commit 4a0c4bb

Please sign in to comment.