Skip to content

Commit

Permalink
review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
lrytz committed Nov 1, 2021
1 parent 9a9f052 commit 2133b3f
Showing 1 changed file with 9 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,15 @@ private abstract class PreservingBuilder[A, C <: TraversableOnce[A]] extends m.B
ruined = true
}

override def ++=(elems: TraversableOnce[A]): this.type =
elems match {
case ct(ca) if collection == null && !ruined =>
collection = ca
this
override def ++=(elems: TraversableOnce[A]): this.type = {
(if (collection == null && !ruined) ct.unapply(elems) else None) match {
case Some(c) => collection = c
case _ =>
ruin()
that ++= elems
this
}
this
}

def +=(elem: A): this.type = {
ruin()
Expand All @@ -53,8 +52,10 @@ private abstract class PreservingBuilder[A, C <: TraversableOnce[A]] extends m.B

def clear(): Unit = {
collection = null.asInstanceOf[C]
if (ruined) that.clear()
ruined = false
if (ruined) {
that.clear()
ruined = false
}
}

def result(): C = if (collection == null) that.result() else collection
Expand Down

0 comments on commit 2133b3f

Please sign in to comment.