File tree 1 file changed +23
-15
lines changed
compat/src/main/scala-2.11_2.12/scala/collection/compat
1 file changed +23
-15
lines changed Original file line number Diff line number Diff line change @@ -22,35 +22,43 @@ import scala.collection.{immutable => i, mutable => m}
22
22
*/
23
23
private final class IdentityPreservingBuilder [A , CC [X ] <: TraversableOnce [X ]](that : Builder [A , CC [A ]])(implicit ct : ClassTag [CC [A ]])
24
24
extends Builder [A , CC [A ]] {
25
+
26
+ // invariant: ruined => (collection == null)
25
27
var collection : CC [A ] = null .asInstanceOf [CC [A ]]
26
28
var ruined = false
27
29
30
+ private [this ] def ruin (): Unit = {
31
+ if (collection != null ) that ++= collection
32
+ collection = null .asInstanceOf [CC [A ]]
33
+ ruined = true
34
+ }
35
+
28
36
final override def ++= (elems : TraversableOnce [A ]): this .type =
29
- elems match {
30
- case ct(ca) if (collection == null && ! ruined) => {
31
- collection = ca
32
- this
33
- }
34
- case _ => {
35
- ruined = true
36
- if (collection != null ) that ++= collection
37
- that ++= elems
38
- collection = null .asInstanceOf [CC [A ]]
39
- this
40
- }
37
+ elems match {
38
+ case ct(ca) if (collection == null && ! ruined) => {
39
+ collection = ca
40
+ this
41
41
}
42
+ case _ => {
43
+ ruin()
44
+ that ++= elems
45
+ this
46
+ }
47
+ }
42
48
43
49
final def += (elem : A ): this .type = {
44
- collection = null .asInstanceOf [CC [A ]]
45
- ruined = true
50
+ ruin()
46
51
that += elem
47
52
this
48
53
}
54
+
49
55
final def clear (): Unit = {
50
56
collection = null .asInstanceOf [CC [A ]]
51
57
if (ruined) that.clear()
58
+ ruined = false
52
59
}
53
- final def result (): CC [A ] = if (ruined || (collection == null )) that.result() else collection
60
+
61
+ final def result (): CC [A ] = if (collection == null ) that.result() else collection
54
62
}
55
63
56
64
private [compat] object CompatImpl {
You can’t perform that action at this time.
0 commit comments