diff options
author | Seth Tisue <seth@tisue.net> | 2015-10-16 13:38:20 +0200 |
---|---|---|
committer | Seth Tisue <seth@tisue.net> | 2015-10-16 13:48:14 +0200 |
commit | 3141fdd6628df5c123db0250abc8ccfcf20d7eff (patch) | |
tree | 9f96dbbf3f27dd4ed3105b7b0562c46e39441220 /src/library | |
parent | c99e53e8a05fc5d45f8e8a28da68d3977be65bfa (diff) | |
parent | ae5f0de71686a250d1bfa72db530015c0f9ddb3a (diff) | |
download | scala-3141fdd6628df5c123db0250abc8ccfcf20d7eff.tar.gz scala-3141fdd6628df5c123db0250abc8ccfcf20d7eff.tar.bz2 scala-3141fdd6628df5c123db0250abc8ccfcf20d7eff.zip |
merge 2.11.x onto 2.12.x, Oct 16 2015
there were merge conflicts in the Eclipse config that I resolved with
--ours. I invite @performantdata to submit a followup PR bringing the
Eclipse stuff into a good state on 2.12.x.
there was a test failure in
test/junit/scala/collection/mutable/OpenHashMapTest.scala
due to the 2.12 compiler emitting the field backing a
private var differently (with an unmangled name). Lukas
says the difference is expected, so I just updated the
code in the test.
there were no other merge conflicts.
% git log --decorate --oneline -1 origin/2.11.x | cat
ae5f0de (origin/HEAD, origin/2.11.x) Merge pull request #4791 from performantdata/issue/9508
% git log --decorate --oneline -1 origin/2.12.x | cat
c99e53e (HEAD -> 2.12.x, origin/2.12.x) Merge pull request #4797 from lrytz/M3-versions
% export MB=$(git merge-base 2.12.x origin/2.11.x)
% echo $MB
42cafa21f3c4a08c6dd34608278f810b6ec2886f
% git log --graph --oneline --decorate $MB...origin/2.11.x | cat
* ae5f0de (origin/HEAD, origin/2.11.x) Merge pull request #4791 from performantdata/issue/9508
|\
| * 08dca37 (origin/pull/4791) SI-9508 fix classpaths in Eclipse configuration
* | fe76232 Merge pull request #4798 from performantdata/issue/9513
|\ \
| * | 9c97a7f (origin/pull/4798) Suppress unneeded import.
| * | 30d704d Document some OpenHashMap internal methods.
| * | 1fb32fc SI-9513 decrement "deleted" count in OpenHashMap.put() when slot reused
| |/
* | 14f875c Merge pull request #4788 from dk14/patch-1
|\ \
| * | 42acd55 (origin/pull/4788) explicitly specify insertion-order feature in docs
| /
* | 68ce049 Merge pull request #4771 from som-snytt/issue/9492-here
|\ \
| * | f290962 (origin/pull/4771) SI-9492 Line trimming paste
| * | bc3589d SI-9492 REPL paste here doc
| /
* | 9834fc8 Merge pull request #4610 from todesking/spec-implicits-remove-obsolete
|\ \
| * | 46009b1 (origin/pull/4610) Add view/context-bound parameter ordering rule
| * | 6eba305 Spec: Implicit parameters with context/view bound is allowed since 2.10
| /
* | d792e35 Merge pull request #4789 from janekdb/2.11.x-param-names-predicates-operations
|\ \
| |/
|/|
| * b19a07e (origin/pull/4789) Rename forall, exists and find predicate and operator params.
|/
* 648c7a1 Merge pull request #4790 from SethTisue/issue/9501
|\
| * 40d12f1 (origin/pull/4790) SI-9501 link README to Scala Hacker Guide
* e0b5891 Merge pull request #4786 from performantdata/issue/9506
* 39acad8 (origin/pull/4786) SI-9506 suppress Scala IDE-generated files in the Eclipse project dirs
* 74dc364 SI-9506 suppress Scala IDE-generated files in the Eclipse project dirs
% git merge ae5f0de
Auto-merging src/repl/scala/tools/nsc/interpreter/ILoop.scala
Auto-merging src/library/scala/util/Either.scala
Auto-merging src/library/scala/runtime/Tuple3Zipped.scala
Auto-merging src/library/scala/runtime/Tuple2Zipped.scala
Auto-merging src/library/scala/collection/parallel/ParIterableLike.scala
Auto-merging src/library/scala/collection/immutable/ListMap.scala
Auto-merging src/library/scala/collection/TraversableLike.scala
Auto-merging src/eclipse/test-junit/.classpath
CONFLICT (content): Merge conflict in src/eclipse/test-junit/.classpath
Auto-merging src/eclipse/scaladoc/.classpath
CONFLICT (content): Merge conflict in src/eclipse/scaladoc/.classpath
Auto-merging src/eclipse/scala-compiler/.classpath
Auto-merging src/eclipse/repl/.classpath
CONFLICT (content): Merge conflict in src/eclipse/repl/.classpath
Auto-merging src/eclipse/partest/.classpath
CONFLICT (content): Merge conflict in src/eclipse/partest/.classpath
Auto-merging src/eclipse/interactive/.classpath
Auto-merging README.md
Automatic merge failed; fix conflicts and then commit the result.
% git checkout --ours src/eclipse/partest/.classpath
% git checkout --ours src/eclipse/repl/.classpath
% git checkout --ours src/eclipse/scaladoc/.classpath
% git checkout --ours src/eclipse/test-junit/.classpath
% git add -u
% emacs test/junit/scala/collection/mutable/OpenHashMapTest.scala
% git diff test/junit/scala/collection/mutable/OpenHashMapTest.scala | cat
...
- val field = m.getClass.getDeclaredField("scala$collection$mutable$OpenHashMap$$deleted")
+ val field = m.getClass.getDeclaredField("deleted")
...
% git add -u
Diffstat (limited to 'src/library')
-rw-r--r-- | src/library/scala/collection/GenTraversableOnce.scala | 23 | ||||
-rw-r--r-- | src/library/scala/collection/TraversableLike.scala | 2 | ||||
-rw-r--r-- | src/library/scala/collection/immutable/ListMap.scala | 2 | ||||
-rw-r--r-- | src/library/scala/collection/immutable/RedBlackTree.scala | 4 | ||||
-rw-r--r-- | src/library/scala/collection/immutable/Set.scala | 74 | ||||
-rw-r--r-- | src/library/scala/collection/mutable/OpenHashMap.scala | 19 | ||||
-rw-r--r-- | src/library/scala/collection/parallel/ParIterableLike.scala | 18 | ||||
-rw-r--r-- | src/library/scala/runtime/Tuple2Zipped.scala | 8 | ||||
-rw-r--r-- | src/library/scala/runtime/Tuple3Zipped.scala | 8 | ||||
-rw-r--r-- | src/library/scala/util/Either.scala | 12 |
10 files changed, 101 insertions, 69 deletions
diff --git a/src/library/scala/collection/GenTraversableOnce.scala b/src/library/scala/collection/GenTraversableOnce.scala index f77462ce88..a45ec965f5 100644 --- a/src/library/scala/collection/GenTraversableOnce.scala +++ b/src/library/scala/collection/GenTraversableOnce.scala @@ -393,20 +393,35 @@ trait GenTraversableOnce[+A] extends Any { */ def minBy[B](f: A => B)(implicit cmp: Ordering[B]): A - def forall(pred: A => Boolean): Boolean + /** Tests whether a predicate holds for all elements of this $coll. + * + * $mayNotTerminateInf + * + * @param p the predicate used to test elements. + * @return `true` if this $coll is empty or the given predicate `p` + * holds for all elements of this $coll, otherwise `false`. + */ + def forall(@deprecatedName('pred) p: A => Boolean): Boolean - def exists(pred: A => Boolean): Boolean + /** Tests whether a predicate holds for at least one element of this $coll. + * + * $mayNotTerminateInf + * + * @param p the predicate used to test elements. + * @return `true` if the given predicate `p` is satisfied by at least one element of this $coll, otherwise `false` + */ + def exists(@deprecatedName('pred) p: A => Boolean): Boolean /** Finds the first element of the $coll satisfying a predicate, if any. * * $mayNotTerminateInf * $orderDependent * - * @param pred the predicate used to test elements. + * @param p the predicate used to test elements. * @return an option value containing the first element in the $coll * that satisfies `p`, or `None` if none exists. */ - def find(pred: A => Boolean): Option[A] + def find(@deprecatedName('pred) p: A => Boolean): Option[A] /** Copies values of this $coll to an array. * Fills the given array `xs` with values of this $coll. diff --git a/src/library/scala/collection/TraversableLike.scala b/src/library/scala/collection/TraversableLike.scala index f187a7a655..a0b1430d17 100644 --- a/src/library/scala/collection/TraversableLike.scala +++ b/src/library/scala/collection/TraversableLike.scala @@ -357,7 +357,7 @@ trait TraversableLike[+A, +Repr] extends Any result } - /** Tests whether a predicate holds for some of the elements of this $coll. + /** Tests whether a predicate holds for at least one element of this $coll. * * $mayNotTerminateInf * diff --git a/src/library/scala/collection/immutable/ListMap.scala b/src/library/scala/collection/immutable/ListMap.scala index c5773338f5..c59f4f7436 100644 --- a/src/library/scala/collection/immutable/ListMap.scala +++ b/src/library/scala/collection/immutable/ListMap.scala @@ -36,7 +36,7 @@ object ListMap extends ImmutableMapFactory[ListMap] { } } -/** This class implements immutable maps using a list-based data structure. +/** This class implements immutable maps using a list-based data structure, which preserves insertion order. * Instances of `ListMap` represent empty maps; they can be either created by * calling the constructor directly, or by applying the function `ListMap.empty`. * diff --git a/src/library/scala/collection/immutable/RedBlackTree.scala b/src/library/scala/collection/immutable/RedBlackTree.scala index 7e8cfcc902..afb4c9c552 100644 --- a/src/library/scala/collection/immutable/RedBlackTree.scala +++ b/src/library/scala/collection/immutable/RedBlackTree.scala @@ -409,11 +409,11 @@ object RedBlackTree { def cons[B](x: B, xs: NList[B]): NList[B] = new NList(x, xs) - def foldLeft[A, B](xs: NList[A], z: B)(f: (B, A) => B): B = { + def foldLeft[A, B](xs: NList[A], z: B)(op: (B, A) => B): B = { var acc = z var these = xs while (these ne null) { - acc = f(acc, these.head) + acc = op(acc, these.head) these = these.tail } acc diff --git a/src/library/scala/collection/immutable/Set.scala b/src/library/scala/collection/immutable/Set.scala index a115469b83..031e5248c1 100644 --- a/src/library/scala/collection/immutable/Set.scala +++ b/src/library/scala/collection/immutable/Set.scala @@ -33,7 +33,7 @@ trait Set[A] extends Iterable[A] with Parallelizable[A, ParSet[A]] { override def companion: GenericCompanion[Set] = Set - + /** Returns this $coll as an immutable set, perhaps accepting a * wider range of elements. Since it already is an @@ -63,7 +63,7 @@ trait Set[A] extends Iterable[A] object Set extends ImmutableSetFactory[Set] { /** $setCanBuildFromInfo */ implicit def canBuildFrom[A]: CanBuildFrom[Coll, A, Set[A]] = setCanBuildFrom[A] - + /** An optimized representation for immutable empty sets */ private object EmptySet extends AbstractSet[Any] with Set[Any] with Serializable { override def size: Int = 0 @@ -71,7 +71,7 @@ object Set extends ImmutableSetFactory[Set] { def + (elem: Any): Set[Any] = new Set1(elem) def - (elem: Any): Set[Any] = this def iterator: Iterator[Any] = Iterator.empty - override def foreach[U](f: Any => U): Unit = {} + override def foreach[U](f: Any => U): Unit = () override def toSet[B >: Any]: Set[B] = this.asInstanceOf[Set[B]] } private[collection] def emptyInstance: Set[Any] = EmptySet @@ -90,17 +90,17 @@ object Set extends ImmutableSetFactory[Set] { else this def iterator: Iterator[A] = Iterator(elem1) - override def foreach[U](f: A => U): Unit = { + override def foreach[U](f: A => U): Unit = { f(elem1) } - override def exists(f: A => Boolean): Boolean = { - f(elem1) + override def exists(@deprecatedName('f) p: A => Boolean): Boolean = { + p(elem1) } - override def forall(f: A => Boolean): Boolean = { - f(elem1) + override def forall(@deprecatedName('f) p: A => Boolean): Boolean = { + p(elem1) } - override def find(f: A => Boolean): Option[A] = { - if (f(elem1)) Some(elem1) + override def find(@deprecatedName('f) p: A => Boolean): Option[A] = { + if (p(elem1)) Some(elem1) else None } // Why is Set1 non-final? Need to fix that! @@ -124,18 +124,18 @@ object Set extends ImmutableSetFactory[Set] { else this def iterator: Iterator[A] = Iterator(elem1, elem2) - override def foreach[U](f: A => U): Unit = { + override def foreach[U](f: A => U): Unit = { f(elem1); f(elem2) } - override def exists(f: A => Boolean): Boolean = { - f(elem1) || f(elem2) + override def exists(@deprecatedName('f) p: A => Boolean): Boolean = { + p(elem1) || p(elem2) } - override def forall(f: A => Boolean): Boolean = { - f(elem1) && f(elem2) + override def forall(@deprecatedName('f) p: A => Boolean): Boolean = { + p(elem1) && p(elem2) } - override def find(f: A => Boolean): Option[A] = { - if (f(elem1)) Some(elem1) - else if (f(elem2)) Some(elem2) + override def find(@deprecatedName('f) p: A => Boolean): Option[A] = { + if (p(elem1)) Some(elem1) + else if (p(elem2)) Some(elem2) else None } // Why is Set2 non-final? Need to fix that! @@ -159,19 +159,19 @@ object Set extends ImmutableSetFactory[Set] { else this def iterator: Iterator[A] = Iterator(elem1, elem2, elem3) - override def foreach[U](f: A => U): Unit = { + override def foreach[U](f: A => U): Unit = { f(elem1); f(elem2); f(elem3) } - override def exists(f: A => Boolean): Boolean = { - f(elem1) || f(elem2) || f(elem3) + override def exists(@deprecatedName('f) p: A => Boolean): Boolean = { + p(elem1) || p(elem2) || p(elem3) } - override def forall(f: A => Boolean): Boolean = { - f(elem1) && f(elem2) && f(elem3) + override def forall(@deprecatedName('f) p: A => Boolean): Boolean = { + p(elem1) && p(elem2) && p(elem3) } - override def find(f: A => Boolean): Option[A] = { - if (f(elem1)) Some(elem1) - else if (f(elem2)) Some(elem2) - else if (f(elem3)) Some(elem3) + override def find(@deprecatedName('f) p: A => Boolean): Option[A] = { + if (p(elem1)) Some(elem1) + else if (p(elem2)) Some(elem2) + else if (p(elem3)) Some(elem3) else None } // Why is Set3 non-final? Need to fix that! @@ -196,20 +196,20 @@ object Set extends ImmutableSetFactory[Set] { else this def iterator: Iterator[A] = Iterator(elem1, elem2, elem3, elem4) - override def foreach[U](f: A => U): Unit = { + override def foreach[U](f: A => U): Unit = { f(elem1); f(elem2); f(elem3); f(elem4) } - override def exists(f: A => Boolean): Boolean = { - f(elem1) || f(elem2) || f(elem3) || f(elem4) + override def exists(@deprecatedName('f) p: A => Boolean): Boolean = { + p(elem1) || p(elem2) || p(elem3) || p(elem4) } - override def forall(f: A => Boolean): Boolean = { - f(elem1) && f(elem2) && f(elem3) && f(elem4) + override def forall(@deprecatedName('f) p: A => Boolean): Boolean = { + p(elem1) && p(elem2) && p(elem3) && p(elem4) } - override def find(f: A => Boolean): Option[A] = { - if (f(elem1)) Some(elem1) - else if (f(elem2)) Some(elem2) - else if (f(elem3)) Some(elem3) - else if (f(elem4)) Some(elem4) + override def find(@deprecatedName('f) p: A => Boolean): Option[A] = { + if (p(elem1)) Some(elem1) + else if (p(elem2)) Some(elem2) + else if (p(elem3)) Some(elem3) + else if (p(elem4)) Some(elem4) else None } // Why is Set4 non-final? Need to fix that! diff --git a/src/library/scala/collection/mutable/OpenHashMap.scala b/src/library/scala/collection/mutable/OpenHashMap.scala index 24f5761cf5..5f8f5b9a0a 100644 --- a/src/library/scala/collection/mutable/OpenHashMap.scala +++ b/src/library/scala/collection/mutable/OpenHashMap.scala @@ -81,6 +81,9 @@ extends AbstractMap[Key, Value] h ^ (h >>> 7) ^ (h >>> 4) } + /** Increase the size of the table. + * Copy only the occupied slots, effectively eliminating the deleted slots. + */ private[this] def growTable() = { val oldSize = mask + 1 val newSize = 4 * oldSize @@ -92,8 +95,18 @@ extends AbstractMap[Key, Value] deleted = 0 } + /** Return the index of the first slot in the hash table (in probe order) + * that either is empty, or is or was last occupied by the given key. + */ private[this] def findIndex(key: Key) : Int = findIndex(key, hashOf(key)) + /** Return the index of the first slot in the hash table (in probe order) + * that either is empty, or is or was last occupied by the given key. + * + * This method is an optimization for when the hash value is in hand. + * + * @param hash hash value for `key` + */ private[this] def findIndex(key: Key, hash: Int): Int = { var j = hash @@ -136,7 +149,11 @@ extends AbstractMap[Key, Value] None } else { val res = entry.value - if (entry.value == None) { size += 1; modCount += 1 } + if (entry.value == None) { + size += 1 + deleted -= 1 + modCount += 1 + } entry.value = Some(value) res } diff --git a/src/library/scala/collection/parallel/ParIterableLike.scala b/src/library/scala/collection/parallel/ParIterableLike.scala index 53f9a7b87a..a5a82764d6 100644 --- a/src/library/scala/collection/parallel/ParIterableLike.scala +++ b/src/library/scala/collection/parallel/ParIterableLike.scala @@ -520,22 +520,22 @@ self: ParIterableLike[T, Repr, Sequential] => * * $abortsignalling * - * @param pred a predicate used to test elements + * @param p a predicate used to test elements * @return true if `p` holds for all elements, false otherwise */ - def forall(pred: T => Boolean): Boolean = { - tasksupport.executeAndWaitResult(new Forall(pred, splitter assign new DefaultSignalling with VolatileAbort)) + def forall(@deprecatedName('pred) p: T => Boolean): Boolean = { + tasksupport.executeAndWaitResult(new Forall(p, splitter assign new DefaultSignalling with VolatileAbort)) } /** Tests whether a predicate holds for some element of this $coll. * * $abortsignalling * - * @param pred a predicate used to test elements + * @param p a predicate used to test elements * @return true if `p` holds for some element, false otherwise */ - def exists(pred: T => Boolean): Boolean = { - tasksupport.executeAndWaitResult(new Exists(pred, splitter assign new DefaultSignalling with VolatileAbort)) + def exists(@deprecatedName('pred) p: T => Boolean): Boolean = { + tasksupport.executeAndWaitResult(new Exists(p, splitter assign new DefaultSignalling with VolatileAbort)) } /** Finds some element in the collection for which the predicate holds, if such @@ -546,11 +546,11 @@ self: ParIterableLike[T, Repr, Sequential] => * * $abortsignalling * - * @param pred predicate used to test the elements + * @param p predicate used to test the elements * @return an option value with the element if such an element exists, or `None` otherwise */ - def find(pred: T => Boolean): Option[T] = { - tasksupport.executeAndWaitResult(new Find(pred, splitter assign new DefaultSignalling with VolatileAbort)) + def find(@deprecatedName('pred) p: T => Boolean): Option[T] = { + tasksupport.executeAndWaitResult(new Find(p, splitter assign new DefaultSignalling with VolatileAbort)) } /** Creates a combiner factory. Each combiner factory instance is used diff --git a/src/library/scala/runtime/Tuple2Zipped.scala b/src/library/scala/runtime/Tuple2Zipped.scala index 1c432b0403..15331d4160 100644 --- a/src/library/scala/runtime/Tuple2Zipped.scala +++ b/src/library/scala/runtime/Tuple2Zipped.scala @@ -84,12 +84,12 @@ final class Tuple2Zipped[El1, Repr1, El2, Repr2](val colls: (TraversableLike[El1 (b1.result(), b2.result()) } - def exists(f: (El1, El2) => Boolean): Boolean = { + def exists(@deprecatedName('f) p: (El1, El2) => Boolean): Boolean = { val elems2 = colls._2.iterator for (el1 <- colls._1) { if (elems2.hasNext) { - if (f(el1, elems2.next())) + if (p(el1, elems2.next())) return true } else return false @@ -97,8 +97,8 @@ final class Tuple2Zipped[El1, Repr1, El2, Repr2](val colls: (TraversableLike[El1 false } - def forall(f: (El1, El2) => Boolean): Boolean = - !exists((x, y) => !f(x, y)) + def forall(@deprecatedName('f) p: (El1, El2) => Boolean): Boolean = + !exists((x, y) => !p(x, y)) def foreach[U](f: (El1, El2) => U): Unit = { val elems2 = colls._2.iterator diff --git a/src/library/scala/runtime/Tuple3Zipped.scala b/src/library/scala/runtime/Tuple3Zipped.scala index 3bab86921b..62bee5ff0e 100644 --- a/src/library/scala/runtime/Tuple3Zipped.scala +++ b/src/library/scala/runtime/Tuple3Zipped.scala @@ -90,13 +90,13 @@ final class Tuple3Zipped[El1, Repr1, El2, Repr2, El3, Repr3](val colls: (Travers result } - def exists(f: (El1, El2, El3) => Boolean): Boolean = { + def exists(@deprecatedName('f) p: (El1, El2, El3) => Boolean): Boolean = { val elems2 = colls._2.iterator val elems3 = colls._3.iterator for (el1 <- colls._1) { if (elems2.hasNext && elems3.hasNext) { - if (f(el1, elems2.next(), elems3.next())) + if (p(el1, elems2.next(), elems3.next())) return true } else return false @@ -104,8 +104,8 @@ final class Tuple3Zipped[El1, Repr1, El2, Repr2, El3, Repr3](val colls: (Travers false } - def forall(f: (El1, El2, El3) => Boolean): Boolean = - !exists((x, y, z) => !f(x, y, z)) + def forall(@deprecatedName('f) p: (El1, El2, El3) => Boolean): Boolean = + !exists((x, y, z) => !p(x, y, z)) def foreach[U](f: (El1, El2, El3) => U): Unit = { val elems2 = colls._2.iterator diff --git a/src/library/scala/util/Either.scala b/src/library/scala/util/Either.scala index 6ea9da64f2..675b3c8c61 100644 --- a/src/library/scala/util/Either.scala +++ b/src/library/scala/util/Either.scala @@ -329,8 +329,8 @@ object Either { * }}} * */ - def forall(f: A => Boolean) = e match { - case Left(a) => f(a) + def forall(@deprecatedName('f) p: A => Boolean) = e match { + case Left(a) => p(a) case Right(_) => true } @@ -345,8 +345,8 @@ object Either { * }}} * */ - def exists(f: A => Boolean) = e match { - case Left(a) => f(a) + def exists(@deprecatedName('f) p: A => Boolean) = e match { + case Left(a) => p(a) case Right(_) => false } @@ -507,9 +507,9 @@ object Either { * Left(12).right.exists(_ > 10) // false * }}} */ - def exists(f: B => Boolean) = e match { + def exists(@deprecatedName('f) p: B => Boolean) = e match { case Left(_) => false - case Right(b) => f(b) + case Right(b) => p(b) } /** |