diff options
author | Lukas Rytz <lukas.rytz@gmail.com> | 2015-04-01 16:47:22 +0200 |
---|---|---|
committer | Lukas Rytz <lukas.rytz@gmail.com> | 2015-04-01 16:47:22 +0200 |
commit | dcd9a83916f9e0128ef6869def82d4f23bdea0e0 (patch) | |
tree | e58331aebe8ba06fd1c15faf36fdbb3f77b489b9 /src/library/scala/collection/immutable | |
parent | ebf0976c363c67e6a46c66d70b39704f1ce5e74a (diff) | |
parent | fcc20fe4d3ac5caceb50965bc202b880e61f984c (diff) | |
download | scala-dcd9a83916f9e0128ef6869def82d4f23bdea0e0.tar.gz scala-dcd9a83916f9e0128ef6869def82d4f23bdea0e0.tar.bz2 scala-dcd9a83916f9e0128ef6869def82d4f23bdea0e0.zip |
Merge commit 'fcc20fe' into merge/2.11-to-2.12-apr-1
Diffstat (limited to 'src/library/scala/collection/immutable')
4 files changed, 43 insertions, 13 deletions
diff --git a/src/library/scala/collection/immutable/List.scala b/src/library/scala/collection/immutable/List.scala index 89b4ee1145..48a6ca5699 100644 --- a/src/library/scala/collection/immutable/List.scala +++ b/src/library/scala/collection/immutable/List.scala @@ -324,7 +324,7 @@ sealed abstract class List[+A] extends AbstractSeq[A] var h: ::[B] = null var t: ::[B] = null while (rest ne Nil) { - f(rest.head).foreach{ b => + f(rest.head).seq.foreach{ b => if (!found) { h = new ::(b, Nil) t = h diff --git a/src/library/scala/collection/immutable/Stream.scala b/src/library/scala/collection/immutable/Stream.scala index 8be0b2fee2..5fff727c36 100644 --- a/src/library/scala/collection/immutable/Stream.scala +++ b/src/library/scala/collection/immutable/Stream.scala @@ -697,16 +697,18 @@ self => b append end return b } - if ((cursor ne scout) && scout.tailDefined) { + if (cursor ne scout) { cursor = scout - scout = scout.tail - // Use 2x 1x iterator trick for cycle detection; slow iterator can add strings - while ((cursor ne scout) && scout.tailDefined) { - b append sep append cursor.head - n += 1 - cursor = cursor.tail + if (scout.tailDefined) { scout = scout.tail - if (scout.tailDefined) scout = scout.tail + // Use 2x 1x iterator trick for cycle detection; slow iterator can add strings + while ((cursor ne scout) && scout.tailDefined) { + b append sep append cursor.head + n += 1 + cursor = cursor.tail + scout = scout.tail + if (scout.tailDefined) scout = scout.tail + } } } if (!scout.tailDefined) { // Not a cycle, scout hit an end @@ -715,6 +717,9 @@ self => n += 1 cursor = cursor.tail } + if (cursor.nonEmpty) { + b append sep append cursor.head + } } else { // Cycle. diff --git a/src/library/scala/collection/immutable/StringLike.scala b/src/library/scala/collection/immutable/StringLike.scala index f0daaf25a5..1ead894faf 100644 --- a/src/library/scala/collection/immutable/StringLike.scala +++ b/src/library/scala/collection/immutable/StringLike.scala @@ -10,7 +10,7 @@ package scala package collection package immutable -import mutable.Builder +import mutable.{ ArrayBuilder, Builder } import scala.util.matching.Regex import scala.math.ScalaNumber import scala.reflect.ClassTag @@ -203,8 +203,33 @@ self => private def escape(ch: Char): String = "\\Q" + ch + "\\E" - @throws(classOf[java.util.regex.PatternSyntaxException]) - def split(separator: Char): Array[String] = toString.split(escape(separator)) + def split(separator: Char): Array[String] = { + val thisString = toString + var pos = thisString.indexOf(separator) + + if (pos != -1) { + val res = new ArrayBuilder.ofRef[String] + + var prev = 0 + do { + res += thisString.substring(prev, pos) + prev = pos + 1 + pos = thisString.indexOf(separator, prev) + } while (pos != -1) + + if (prev != thisString.size) + res += thisString.substring(prev, thisString.size) + + val initialResult = res.result() + pos = initialResult.length + while (pos > 0 && initialResult(pos - 1).isEmpty) pos = pos - 1 + if (pos != initialResult.length) { + val trimmed = new Array[String](pos) + Array.copy(initialResult, 0, trimmed, 0, pos) + trimmed + } else initialResult + } else Array[String](thisString) + } @throws(classOf[java.util.regex.PatternSyntaxException]) def split(separators: Array[Char]): Array[String] = { diff --git a/src/library/scala/collection/immutable/Vector.scala b/src/library/scala/collection/immutable/Vector.scala index c7da447f72..47a623a616 100644 --- a/src/library/scala/collection/immutable/Vector.scala +++ b/src/library/scala/collection/immutable/Vector.scala @@ -215,7 +215,7 @@ override def companion: GenericCompanion[Vector] = Vector import Vector.{Log2ConcatFaster, TinyAppendFaster} if (that.isEmpty) this.asInstanceOf[That] else { - val again = if (!that.isTraversableAgain) that.toVector else that + val again = if (!that.isTraversableAgain) that.toVector else that.seq again.size match { // Often it's better to append small numbers of elements (or prepend if RHS is a vector) case n if n <= TinyAppendFaster || n < (this.size >> Log2ConcatFaster) => |