diff options
author | Paul Phillips <paulp@improving.org> | 2012-11-23 20:10:28 -0800 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2012-11-23 20:12:42 -0800 |
commit | f0e9237834d00ea9e27937e44dc8b8382be32db6 (patch) | |
tree | 9807c35aa0bc818bf487a2c93bd577e37e1adce0 /src/library/scala/collection/mutable/ListBuffer.scala | |
parent | 889ceade520ae5d2d1485edf2826696fa91a0e91 (diff) | |
parent | faa6cfcf404b4d172f20b3ed01ba3bd59427b700 (diff) | |
download | scala-f0e9237834d00ea9e27937e44dc8b8382be32db6.tar.gz scala-f0e9237834d00ea9e27937e44dc8b8382be32db6.tar.bz2 scala-f0e9237834d00ea9e27937e44dc8b8382be32db6.zip |
Merge branch 'merge-2.10.wip-x' into merge-2.10.x-master
* merge-2.10.wip-x: (24 commits)
SI-6023 reify abstract vals
Removing controversial `either` method from Futures API.
SI-6695 Test case for fixed Array match bug
adds comments to standard attachments
SI-6673 fixes macro problems with eta expansions
Restore the opimization apparently lost after merge.
SI-6624 set info of case pattern binder to help find case field accessors
Scaladoc update for collection.mutable.MultiMap
SI-6663: don't ignore type parameter on selectDynamic invocation
SI-6551: don't insert apply call in polymorphic expression.
SI-6634 Fixes data corruption issue in ListBuffer#remove
Fixes SI-6628, Revert "Fix for view isEmpty."
SI-6661 - Remove obsolete implicit parameter of scala.concurrent.promise method
Fixes SI-6150 - backport to 2.10.x branch.
SI-5330, SI-6014 deal with existential self-type
Fixes SI-6559 - StringContext not using passed in escape function.
SI-6648 copyAttrs must preserve TypeTree#wasEmpty
Fix raw string interpolator: string parts which were after the first argument were still escaped
sane printing of renamed imports
SI-6440 Address regressions around MissingRequirementError
...
Conflicts:
src/library/scala/collection/generic/IndexedSeqFactory.scala
src/library/scala/collection/mutable/ListBuffer.scala
src/reflect/scala/reflect/internal/Symbols.scala
src/reflect/scala/reflect/internal/Types.scala
test/files/run/t6150.scala
Diffstat (limited to 'src/library/scala/collection/mutable/ListBuffer.scala')
-rw-r--r-- | src/library/scala/collection/mutable/ListBuffer.scala | 98 |
1 files changed, 49 insertions, 49 deletions
diff --git a/src/library/scala/collection/mutable/ListBuffer.scala b/src/library/scala/collection/mutable/ListBuffer.scala index bc38768e29..b7b487964c 100644 --- a/src/library/scala/collection/mutable/ListBuffer.scala +++ b/src/library/scala/collection/mutable/ListBuffer.scala @@ -135,29 +135,27 @@ final class ListBuffer[A] * @throws Predef.IndexOutOfBoundsException if `n` is out of bounds. */ def update(n: Int, x: A) { - try { - if (exported) copy() - if (n == 0) { - val newElem = new :: (x, start.tail); - if ((last0 eq null) || (last0 eq start)) { - last0 = newElem - } - start = newElem - } else { - var cursor = start - var i = 1 - while (i < n) { - cursor = cursor.tail - i += 1 - } - val newElem = new :: (x, cursor.tail.tail) - if (last0 eq cursor.tail) { - last0 = newElem - } - cursor.asInstanceOf[::[A]].tl = newElem + // We check the bounds early, so that we don't trigger copying. + if (n < 0 || n >= len) throw new IndexOutOfBoundsException(n.toString) + if (exported) copy() + if (n == 0) { + val newElem = new :: (x, start.tail); + if (last0 eq start) { + last0 = newElem + } + start = newElem + } else { + var cursor = start + var i = 1 + while (i < n) { + cursor = cursor.tail + i += 1 + } + val newElem = new :: (x, cursor.tail.tail) + if (last0 eq cursor.tail) { + last0 = newElem } - } catch { - case ex: Exception => throw new IndexOutOfBoundsException(n.toString()) + cursor.asInstanceOf[::[A]].tl = newElem } } @@ -219,34 +217,31 @@ final class ListBuffer[A] * @throws Predef.IndexOutOfBoundsException if `n` is out of bounds. */ def insertAll(n: Int, seq: Traversable[A]) { - try { - if (exported) copy() - var elems = seq.toList.reverse - len += elems.length - if (n == 0) { - while (!elems.isEmpty) { - val newElem = new :: (elems.head, start) - if (isEmpty) last0 = newElem - start = newElem - elems = elems.tail - } - } else { - var cursor = start - var i = 1 - while (i < n) { - cursor = cursor.tail - i += 1 - } - while (!elems.isEmpty) { - val newElem = new :: (elems.head, cursor.tail) - if (cursor.tail.isEmpty) last0 = newElem - cursor.asInstanceOf[::[A]].tl = newElem - elems = elems.tail - } + // We check the bounds early, so that we don't trigger copying. + if (n < 0 || n > len) throw new IndexOutOfBoundsException(n.toString) + if (exported) copy() + var elems = seq.toList.reverse + len += elems.length + if (n == 0) { + while (!elems.isEmpty) { + val newElem = new :: (elems.head, start) + if (start.isEmpty) last0 = newElem + start = newElem + elems = elems.tail + } + } else { + var cursor = start + var i = 1 + while (i < n) { + cursor = cursor.tail + i += 1 + } + while (!elems.isEmpty) { + val newElem = new :: (elems.head, cursor.tail) + if (cursor.tail.isEmpty) last0 = newElem + cursor.asInstanceOf[::[A]].tl = newElem + elems = elems.tail } - } catch { - case ex: Exception => - throw new IndexOutOfBoundsException(n.toString()) } } @@ -265,7 +260,12 @@ final class ListBuffer[A] * @param n the index which refers to the first element to remove. * @param count the number of elements to remove. */ + @annotation.migration("Invalid input values will be rejected in future releases.", "2.11") override def remove(n: Int, count: Int) { + if (n >= len) + return + if (count < 0) + throw new IllegalArgumentException(s"removing negative number ($count) of elements") if (exported) copy() val n1 = n max 0 val count1 = count min (len - n1) |