summaryrefslogtreecommitdiff
path: root/src/library/scala/collection/mutable/Builder.scala
diff options
context:
space:
mode:
authorGrzegorz Kossakowski <grzegorz.kossakowski@gmail.com>2012-08-20 11:27:25 +0100
committerGrzegorz Kossakowski <grzegorz.kossakowski@gmail.com>2012-08-20 11:27:25 +0100
commitdf9f470f14262b9b1002f022c2620d8c38835805 (patch)
tree4e9a18a1aff2af3c8a89c6c71e8aab34b1b4e3af /src/library/scala/collection/mutable/Builder.scala
parentebb719fb92a50476ba51e4be8e87571ff4949551 (diff)
downloadscala-df9f470f14262b9b1002f022c2620d8c38835805.tar.gz
scala-df9f470f14262b9b1002f022c2620d8c38835805.tar.bz2
scala-df9f470f14262b9b1002f022c2620d8c38835805.zip
Attempts to improve inlining behavior for map, flatMap.
Reduced method size of map/flatMap to under 35 bytes to make them inlinable. Also specialized filterNot code so that it does not create a second closure. Finally, avoided default argument for sizeHint to reduce size of methods calling it.
Diffstat (limited to 'src/library/scala/collection/mutable/Builder.scala')
-rw-r--r--src/library/scala/collection/mutable/Builder.scala20
1 files changed, 19 insertions, 1 deletions
diff --git a/src/library/scala/collection/mutable/Builder.scala b/src/library/scala/collection/mutable/Builder.scala
index bbf4f5889d..b6887df61e 100644
--- a/src/library/scala/collection/mutable/Builder.scala
+++ b/src/library/scala/collection/mutable/Builder.scala
@@ -62,9 +62,27 @@ trait Builder[-Elem, +To] extends Growable[Elem] {
* wrong, i.e. a different number of elements is added.
*
* @param coll the collection which serves as a hint for the result's size.
+ */
+ def sizeHint(coll: TraversableLike[_, _]) {
+ if (coll.isInstanceOf[collection.IndexedSeqLike[_,_]]) {
+ sizeHint(coll.size)
+ }
+ }
+
+ /** Gives a hint that one expects the `result` of this builder
+ * to have the same size as the given collection, plus some delta. This will
+ * provide a hint only if the collection is known to have a cheap
+ * `size` method. Currently this is assumed to be the case if and only if
+ * the collection is of type `IndexedSeqLike`.
+ * Some builder classes
+ * will optimize their representation based on the hint. However,
+ * builder implementations are still required to work correctly even if the hint is
+ * wrong, i.e. a different number of elements is added.
+ *
+ * @param coll the collection which serves as a hint for the result's size.
* @param delta a correction to add to the `coll.size` to produce the size hint.
*/
- def sizeHint(coll: TraversableLike[_, _], delta: Int = 0) {
+ def sizeHint(coll: TraversableLike[_, _], delta: Int) {
if (coll.isInstanceOf[collection.IndexedSeqLike[_,_]]) {
sizeHint(coll.size + delta)
}