diff options
author | Erik Rozendaal <erik@deler.org> | 2011-12-27 15:44:33 +0100 |
---|---|---|
committer | Erik Rozendaal <erik@deler.org> | 2011-12-28 13:12:35 +0100 |
commit | 4a0c4bbd092af26c8c6eea10e668e2cbc3c366a7 (patch) | |
tree | c31934485d1148221ce7412b18e1671a240ab628 | |
parent | b421bba4f570032a23623cfeff41198aabc1d614 (diff) | |
download | scala-4a0c4bbd092af26c8c6eea10e668e2cbc3c366a7.tar.gz scala-4a0c4bbd092af26c8c6eea10e668e2cbc3c366a7.tar.bz2 scala-4a0c4bbd092af26c8c6eea10e668e2cbc3c366a7.zip |
Improved performance of RedBlack.NonEmpty.nth (helps take/drop/split/etc).
-rw-r--r-- | src/library/scala/collection/immutable/RedBlack.scala | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/src/library/scala/collection/immutable/RedBlack.scala b/src/library/scala/collection/immutable/RedBlack.scala index 8e10a8ac4d..3922aded5e 100644 --- a/src/library/scala/collection/immutable/RedBlack.scala +++ b/src/library/scala/collection/immutable/RedBlack.scala @@ -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 } } |