From 40c11466e6235b6834093b79b12fb5e2bf7807f9 Mon Sep 17 00:00:00 2001 From: Iulian Dragos Date: Wed, 13 May 2009 15:12:24 +0000 Subject: Optimiser-friendly changes to Range for more ef... Optimiser-friendly changes to Range for more efficient loops. --- src/library/scala/Range.scala | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'src/library') diff --git a/src/library/scala/Range.scala b/src/library/scala/Range.scala index 8a6ba86bff..dbd4f82f69 100644 --- a/src/library/scala/Range.scala +++ b/src/library/scala/Range.scala @@ -170,7 +170,7 @@ extends VectorView[Int, Vector[Int]] with RangeToString[Int] */ def by(step: Int): Range = new Range(start, end, step) - override def foreach[U](f: Int => U) { + final override def foreach[U](f: Int => U) { var i = start if (step > 0) { while (i < end) { @@ -192,7 +192,8 @@ extends VectorView[Int, Vector[Int]] with RangeToString[Int] else plen(end, start, -step) } - def apply(idx: Int): Int = { + @inline + final def apply(idx: Int): Int = { if (idx < 0 || idx >= length) throw new IndexOutOfBoundsException(idx.toString) start + idx * step } @@ -206,7 +207,7 @@ extends VectorView[Int, Vector[Int]] with RangeToString[Int] object Range { /** @deprecated use Range.inclusive instead */ - class Inclusive(start: Int, end0: Int, step: Int) + final class Inclusive(start: Int, end0: Int, step: Int) extends Range(start, if (step > 0) end0 + 1 else end0 - 1, step) { self => override def by(step: Int): Range = new Inclusive(start, end0, step) } -- cgit v1.2.3