diff options
Diffstat (limited to 'src/library')
-rw-r--r-- | src/library/scala/Array.scala | 17 | ||||
-rw-r--r-- | src/library/scala/collection/generic/TraversableFactory.scala | 16 | ||||
-rw-r--r-- | src/library/scala/collection/immutable/StringOps.scala | 12 | ||||
-rw-r--r-- | src/library/scala/collection/mutable/DoubleLinkedList.scala | 16 | ||||
-rw-r--r-- | src/library/scala/collection/mutable/LinkedListLike.scala | 3 | ||||
-rw-r--r-- | src/library/scala/io/Source.scala | 10 | ||||
-rw-r--r-- | src/library/scala/xml/parsing/MarkupParser.scala | 6 |
7 files changed, 51 insertions, 29 deletions
diff --git a/src/library/scala/Array.scala b/src/library/scala/Array.scala index 8327b93d66..e7ee280cef 100644 --- a/src/library/scala/Array.scala +++ b/src/library/scala/Array.scala @@ -391,13 +391,18 @@ object Array extends FallbackArrayBuilding { */ def iterate[T: ClassManifest](start: T, len: Int)(f: T => T): Array[T] = { val b = newBuilder[T] - b.sizeHint(len) - var acc = start - var i = 0 - while (i < len) { + + if (len > 0) { + b.sizeHint(len) + var acc = start + var i = 1 b += acc - acc = f(acc) - i += 1 + + while (i < len) { + acc = f(acc) + i += 1 + b += acc + } } b.result } diff --git a/src/library/scala/collection/generic/TraversableFactory.scala b/src/library/scala/collection/generic/TraversableFactory.scala index d8541d2714..c6f5ce4dde 100644 --- a/src/library/scala/collection/generic/TraversableFactory.scala +++ b/src/library/scala/collection/generic/TraversableFactory.scala @@ -224,13 +224,17 @@ abstract class TraversableFactory[CC[X] <: Traversable[X] with GenericTraversabl */ def iterate[A](start: A, len: Int)(f: A => A): CC[A] = { val b = newBuilder[A] - b.sizeHint(len) - var acc = start - var i = 0 - while (i < len) { + if (len > 0) { + b.sizeHint(len) + var acc = start + var i = 1 b += acc - acc = f(acc) - i += 1 + + while (i < len) { + acc = f(acc) + i += 1 + b += acc + } } b.result } diff --git a/src/library/scala/collection/immutable/StringOps.scala b/src/library/scala/collection/immutable/StringOps.scala index 8a27a4ad4b..0d8f5f6b83 100644 --- a/src/library/scala/collection/immutable/StringOps.scala +++ b/src/library/scala/collection/immutable/StringOps.scala @@ -36,8 +36,16 @@ final class StringOps(override val repr: String) extends StringLike[String] { /** Creates a string builder buffer as builder for this class */ override protected[this] def newBuilder = new StringBuilder - override def slice(from: Int, until: Int): String = - repr.substring(from max 0, until min repr.length) + override def slice(from: Int, until: Int): String = { + /** Slice must be forgiving on all out of bounds indices and + * substring is not. + */ + val start = from max 0 + val end = until min repr.length + + if (start >= end) "" + else repr.substring(start, end) + } override def toString = repr } diff --git a/src/library/scala/collection/mutable/DoubleLinkedList.scala b/src/library/scala/collection/mutable/DoubleLinkedList.scala index e702301703..d3c86953c8 100644 --- a/src/library/scala/collection/mutable/DoubleLinkedList.scala +++ b/src/library/scala/collection/mutable/DoubleLinkedList.scala @@ -69,15 +69,21 @@ object DoubleLinkedList extends SeqFactory[DoubleLinkedList] { def newBuilder[A]: Builder[A, DoubleLinkedList[A]] = new Builder[A, DoubleLinkedList[A]] { var current: DoubleLinkedList[A] = _ + val emptyList = new DoubleLinkedList[A]() + if(null == current) + current = emptyList + def +=(elem: A): this.type = { - val tmp = new DoubleLinkedList(elem, null) - if (current != null) - current.insert(tmp) + if (current.nonEmpty) + current.insert(new DoubleLinkedList(elem, emptyList)) else - current = tmp + current = new DoubleLinkedList(elem, emptyList) this } - def clear() { current = null } + + def clear() { + current = emptyList + } def result() = current } } diff --git a/src/library/scala/collection/mutable/LinkedListLike.scala b/src/library/scala/collection/mutable/LinkedListLike.scala index ca904e0a24..6fb516d566 100644 --- a/src/library/scala/collection/mutable/LinkedListLike.scala +++ b/src/library/scala/collection/mutable/LinkedListLike.scala @@ -66,8 +66,7 @@ trait LinkedListLike[A, This <: Seq[A] with LinkedListLike[A, This]] extends Seq def insert(that: This): Unit = { require(nonEmpty, "insert into empty list") if (that.nonEmpty) { - that.append(next) - next = that + next = next.append(that) } } diff --git a/src/library/scala/io/Source.scala b/src/library/scala/io/Source.scala index 935fe022be..cb7403e255 100644 --- a/src/library/scala/io/Source.scala +++ b/src/library/scala/io/Source.scala @@ -198,7 +198,8 @@ abstract class Source extends Iterator[Char] { * */ @deprecated("Use a collections method such as getLines().toIndexedSeq for random access.") - def getLine(line: Int): String = getLines() drop (line - 1) next + def getLine(line: Int): String = lineNum(line) + private def lineNum(line: Int): String = getLines() drop (line - 1) next class LineIterator() extends Iterator[String] { private[this] val sb = new StringBuilder @@ -298,11 +299,10 @@ abstract class Source extends Iterator[Char] { * @param out PrintStream to use */ def report(pos: Int, msg: String, out: PrintStream) { - val line = Position line pos - val col = Position column pos - val str = getLines() toIndexedSeq line + val line = Position line pos + val col = Position column pos - out println "%s:%d:%d: %s%s%s^".format(descr, line, col, msg, str, spaces(col - 1)) + out println "%s:%d:%d: %s%s%s^".format(descr, line, col, msg, lineNum(line), spaces(col - 1)) } /** diff --git a/src/library/scala/xml/parsing/MarkupParser.scala b/src/library/scala/xml/parsing/MarkupParser.scala index 24e0d78c6f..4f6b89c07b 100644 --- a/src/library/scala/xml/parsing/MarkupParser.scala +++ b/src/library/scala/xml/parsing/MarkupParser.scala @@ -310,7 +310,7 @@ trait MarkupParser extends MarkupParserCommon with TokenTests def xEntityValue(): String = { val endch = ch nextch - while (ch != endch) { + while (ch != endch && !eof) { putChar(ch) nextch } @@ -556,7 +556,7 @@ trait MarkupParser extends MarkupParserCommon with TokenTests if (ch != '\'' && ch != '"') reportSyntaxError("quote ' or \" expected"); nextch - while (ch != endch) { + while (ch != endch && !eof) { putChar(ch) nextch } @@ -572,7 +572,7 @@ trait MarkupParser extends MarkupParserCommon with TokenTests if (ch!='\'' && ch != '"') reportSyntaxError("quote ' or \" expected"); nextch - while (ch != endch) { + while (ch != endch && !eof) { putChar(ch) //Console.println("hello '"+ch+"'"+isPubIDChar(ch)); if (!isPubIDChar(ch)) |