Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: Scala 2.9.2, Scala 2.10.0-M7
    • Fix Version/s: Scala 2.11.0-M2
    • Component/s: Collections
    • Labels:
    • Environment:

      os x 10.7

      Description

      consider the following:

      object Foo {
      
        def foo(x: Int) = {
          var i = 0
          var acc = 0L
          val r = (3 until x)
          while(i < x) {
            acc += r.head
            i += 1
          }
          acc
        }
      
        def callFoo() = {
          val x = foo(100000)
          println(x)
        }
          
      
        def main(args: Array[String]) {
          val in = System.currentTimeMillis()
          for(i <- 0 until 10000) {
            callFoo()
          }
          println( (System.currentTimeMillis - in))
        }
      
      }
      

      This runs in 4100ms on my machine. If you replace head with "start" it's 690ms

      I'm making a pull request. One line change.

        Activity

        Hide
        david hall added a comment -

        Pull request: https://github.com/scala/scala/pull/1496

        One line change:

        index 92ea5d3..ab303dd 100644
        --- a/src/library/scala/collection/immutable/Range.scala
        +++ b/src/library/scala/collection/immutable/Range.scala
        @@ -78,6 +78,7 @@ extends scala.collection.AbstractSeq[Int]
           final val terminalElement = start + numRangeElements * step
         
           override def last = if (isEmpty) Nil.last else lastElement
        +  override def head = if (isEmpty) Nil.head else start
         
           override def min[A1 >: Int](implicit ord: Ordering[A1]): Int =
             if (ord eq Ordering.Int) {
        
        Show
        david hall added a comment - Pull request: https://github.com/scala/scala/pull/1496 One line change: index 92ea5d3..ab303dd 100644 --- a/src/library/scala/collection/immutable/Range.scala +++ b/src/library/scala/collection/immutable/Range.scala @@ -78,6 +78,7 @@ extends scala.collection.AbstractSeq[Int] final val terminalElement = start + numRangeElements * step override def last = if (isEmpty) Nil.last else lastElement + override def head = if (isEmpty) Nil.head else start override def min[A1 >: Int](implicit ord: Ordering[A1]): Int = if (ord eq Ordering.Int) {
        Hide
        Adriaan Moors added a comment -

        fixed for 2.11.x
        leaving open for backport to 2.10.x

        Show
        Adriaan Moors added a comment - fixed for 2.11.x leaving open for backport to 2.10.x
        Hide
        Adriaan Moors added a comment -

        James, could you look into backporting?

        Show
        Adriaan Moors added a comment - James, could you look into backporting?
        Show
        James Iry added a comment - https://github.com/scala/scala/pull/1866
        Hide
        Adriaan Moors added a comment - - edited

        Due to binary compatibility reasons, this cannot go into 2.10.1-RC1.

        See https://github.com/scala/scala/pull/2103.

        Show
        Adriaan Moors added a comment - - edited Due to binary compatibility reasons, this cannot go into 2.10.1-RC1. See https://github.com/scala/scala/pull/2103 .

          People

          • Assignee:
            James Iry
            Reporter:
            david hall
          • Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development