Uploaded image for project: 'Scala Programming Language'
  1. Scala Programming Language
  2. SI-5286

avoid duplicating more than once a closure body when inlining a closure

    Details

    • Type: Improvement
    • Status: Open
    • Priority: Major
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: Backlog
    • Component/s: Optimizer
    • Labels:

      Description

      immutable.Range.foreach() invokes its argument's apply() twice. When compiling with -optimize, that leads to inlining twice "the loop body" (if it gets inlined at all, for the max size threshold might be surpassed due to the duplicate inlining).

      A formulation of immutable.Range.foreach() invoking its argument's apply() just once is:

      if (length > 0) {
        val sentinel = last
        var closuVar = start
        var loopCond = true
        while ( loopCond ) {
          f(closuVar)
          if(closuVar == sentinel) loopCond = false
          else closuVar += step
        }
      }
      

      There can be other places in the collections library that exhibit a similar pattern.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                magarcia Miguel Garcia
              • Votes:
                0 Vote for this issue
                Watchers:
                7 Start watching this issue

                Dates

                • Created:
                  Updated: