File tree 1 file changed +12
-8
lines changed 1 file changed +12
-8
lines changed Original file line number Diff line number Diff line change @@ -5,12 +5,14 @@ import printing.{Printer, Texts}
5
5
import Texts .Text
6
6
import collection .mutable .{ListBuffer , StringBuilder }
7
7
8
- // List Lst
9
- // 0 0 0
10
- // 1 1 0
11
- // 2 2 1
12
- // 3 3 1
13
- // 4 4 1
8
+
9
+ /** A lightweight class for lists, optimized for short and medium lengths.
10
+ * A list is represented at runtime as
11
+ *
12
+ * If it is empty: the value `Lst.Empty`
13
+ * If it contains one element: the element itself
14
+ * If it contains more elements: an Array[AnyRef] containing the elements
15
+ */
14
16
class Lst [+ T <: AnyRef ](val elems : AnyRef ) extends AnyVal {
15
17
import Lst ._
16
18
@@ -418,8 +420,7 @@ object Lst {
418
420
new Lst (elems)
419
421
}
420
422
421
- val eqFn = (x : AnyRef , y : AnyRef ) => x `eq` y
422
- val equalsFn = (x : AnyRef , y : AnyRef ) => x `equals` y
423
+ private val eqFn = (x : AnyRef , y : AnyRef ) => x `eq` y
423
424
424
425
class Buffer [T <: AnyRef ] {
425
426
private var len = 0
@@ -469,6 +470,9 @@ object Lst {
469
470
if (len == 0 ) Empty
470
471
else if (len == 1 ) new Lst (elem)
471
472
else _fromArray(elems, 0 , len)
473
+
474
+ def clear () =
475
+ len = 0
472
476
}
473
477
474
478
private def _fromArray [T <: AnyRef ](elems : Arr , start : Int , end : Int ): Lst [T ] = {
You can’t perform that action at this time.
0 commit comments