diff options
author | Paul Phillips <paulp@improving.org> | 2010-09-20 06:26:04 +0000 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2010-09-20 06:26:04 +0000 |
commit | e4a596e91d326636fbd68bd9d2b4fc22bae63f76 (patch) | |
tree | 93b1f9759ede1d0f9d2fa3f77d9c64c9cad71ae4 /src | |
parent | 54b5eacb56d21664e53b92d1e5c58195538caef4 (diff) | |
download | scala-e4a596e91d326636fbd68bd9d2b4fc22bae63f76.tar.gz scala-e4a596e91d326636fbd68bd9d2b4fc22bae63f76.tar.bz2 scala-e4a596e91d326636fbd68bd9d2b4fc22bae63f76.zip |
Changed Seq#distinct to use a mutable hashset r...
Changed Seq#distinct to use a mutable hashset rather than an immutable
one in a var. The benchmarks are not close: it's anywhere from 2 to 3
times faster this way. Majority of the credit goes to Tiark for slyly
leaving a comment where I could see it.
TR: should use mutable.HashSet?
PP: yes. yes we should.
Review by community.
Diffstat (limited to 'src')
-rw-r--r-- | src/library/scala/collection/SeqLike.scala | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/src/library/scala/collection/SeqLike.scala b/src/library/scala/collection/SeqLike.scala index 06e8b363c8..d90807437b 100644 --- a/src/library/scala/collection/SeqLike.scala +++ b/src/library/scala/collection/SeqLike.scala @@ -631,11 +631,11 @@ trait SeqLike[+A, +Repr] extends IterableLike[A, Repr] { self => */ def distinct: Repr = { val b = newBuilder - var seen = Set[A]() //TR: should use mutable.HashSet? + val seen = mutable.HashSet[A]() for (x <- this) { - if (!(seen contains x)) { + if (!seen(x)) { b += x - seen = (seen + x) + seen += x } } b.result |