summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBurak Emir <emir@epfl.ch>2006-10-04 09:28:26 +0000
committerBurak Emir <emir@epfl.ch>2006-10-04 09:28:26 +0000
commite1327fc4740baeffcfacdf784a82070b191a58a8 (patch)
treeb5de1fd0d1b0c34411a5ccebd1aa34016ad9802e /src
parent59b5c7d56828f631fe16e59a1f73d7aedf60713e (diff)
downloadscala-e1327fc4740baeffcfacdf784a82070b191a58a8.tar.gz
scala-e1327fc4740baeffcfacdf784a82070b191a58a8.tar.bz2
scala-e1327fc4740baeffcfacdf784a82070b191a58a8.zip
added -= method to Buffer
Diffstat (limited to 'src')
-rw-r--r--src/library/scala/collection/mutable/Buffer.scala10
-rw-r--r--src/library/scala/collection/mutable/ListBuffer.scala5
2 files changed, 13 insertions, 2 deletions
diff --git a/src/library/scala/collection/mutable/Buffer.scala b/src/library/scala/collection/mutable/Buffer.scala
index 86bc87d046..5cec902cff 100644
--- a/src/library/scala/collection/mutable/Buffer.scala
+++ b/src/library/scala/collection/mutable/Buffer.scala
@@ -97,6 +97,16 @@ trait Buffer[A] extends AnyRef
*/
def +:(elem: A): Buffer[A];
+ /** Removes a single element from this buffer, at its first occurrence.
+ * If the list does not contain that element, it is unchanged
+ *
+ * @param x the element to remove.
+ */
+ def -= (x: A): unit = {
+ val i = indexOf(x)
+ if(i != -1) remove(i)
+ }
+
/** Prepends a number of elements provided by an iterable object
* via its <code>elements</code> method. The identity of the
* buffer is returned.
diff --git a/src/library/scala/collection/mutable/ListBuffer.scala b/src/library/scala/collection/mutable/ListBuffer.scala
index eabeabeaa1..66c5dbae27 100644
--- a/src/library/scala/collection/mutable/ListBuffer.scala
+++ b/src/library/scala/collection/mutable/ListBuffer.scala
@@ -60,14 +60,15 @@ final class ListBuffer[A] extends Buffer[A] {
*
* @param x the element to remove.
*/
- def -= (x: A): unit = {
+ override def -= (x: A): unit = {
if (exported) copy()
if (start.isEmpty) {}
else if (start.head == x) start = start.tail
else {
var cursor = start
while (!cursor.tail.isEmpty && cursor.tail.head != x) { cursor = cursor.tail }
- if (!cursor.tail.isEmpty) cursor.asInstanceOf[scala.::[A]].tl = cursor.tail.tail
+ if (!cursor.tail.isEmpty)
+ cursor.asInstanceOf[scala.::[A]].tl = cursor.tail.tail
}
}