diff options
author | Paul Phillips <paulp@improving.org> | 2011-03-12 01:59:46 +0000 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2011-03-12 01:59:46 +0000 |
commit | e86934018bf3078a1a9751c16b95621a04575707 (patch) | |
tree | 37120b7d56e98febc33f3aac3590796e77cc55d0 /src | |
parent | 0254234328ab8a438aac649234bd5e12614f8ff9 (diff) | |
download | scala-e86934018bf3078a1a9751c16b95621a04575707.tar.gz scala-e86934018bf3078a1a9751c16b95621a04575707.tar.bz2 scala-e86934018bf3078a1a9751c16b95621a04575707.zip |
Fixed up the regression I slipped in with slice.
for pointing me toward the problem. No review.
Diffstat (limited to 'src')
-rw-r--r-- | src/library/scala/collection/SeqViewLike.scala | 6 | ||||
-rw-r--r-- | src/library/scala/collection/generic/SliceInterval.scala | 14 |
2 files changed, 16 insertions, 4 deletions
diff --git a/src/library/scala/collection/SeqViewLike.scala b/src/library/scala/collection/SeqViewLike.scala index f5a61ec350..2bd8e29b65 100644 --- a/src/library/scala/collection/SeqViewLike.scala +++ b/src/library/scala/collection/SeqViewLike.scala @@ -194,7 +194,11 @@ trait SeqViewLike[+A, val thatElem = _thatElem } with ZippedAll[A1, B] protected def newReversed: Transformed[A] = new Reversed { } - protected def newPatched[B >: A](_from: Int, _patch: Seq[B], _replaced: Int): Transformed[B] = new { val from = _from; val patch = _patch; val replaced = _replaced } with Patched[B] + protected def newPatched[B >: A](_from: Int, _patch: Seq[B], _replaced: Int): Transformed[B] = new { + val from = _from + val patch = _patch + val replaced = _replaced + } with Patched[B] protected def newPrepended[B >: A](elem: B): Transformed[B] = new { protected[this] val fst = elem } with Prepended[B] override def reverse: This = newReversed.asInstanceOf[This] diff --git a/src/library/scala/collection/generic/SliceInterval.scala b/src/library/scala/collection/generic/SliceInterval.scala index 5c980c7677..56033ca8d8 100644 --- a/src/library/scala/collection/generic/SliceInterval.scala +++ b/src/library/scala/collection/generic/SliceInterval.scala @@ -11,12 +11,14 @@ package generic /** A container for the endpoints of a collection slice. * The constructor is private to enforce the invariants: - * from >= 0 and until >= 0. + * from >= 0, until >= 0, from <= until. */ private[collection] class SliceInterval private (val from: Int, val until: Int) { // The width of this slice from end to end. This is the // maximum size of the collection slice, but the collection - // need not have this many (or any) elements. + // need not have this many (or any) elements. Since + // from <= until is a constructor invariant, we don't have to + // check for negative values. def width = until - from /** Returns a new SliceInterval with endpoints calculated in @@ -41,5 +43,11 @@ private[collection] class SliceInterval private (val from: Int, val until: Int) } object SliceInterval { - def apply(from: Int, until: Int) = new SliceInterval(from max 0, until max 0) + def apply(from: Int, until: Int) = { + val lo = from max 0 + val hi = until max 0 + + if (hi <= lo) new SliceInterval(lo, lo) + else new SliceInterval(lo, hi) + } } |