-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
List(...) optimization to avoid intermediate array (closes #17035)
- Loading branch information
1 parent
d640193
commit 012d456
Showing
4 changed files
with
82 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
object Test: | ||
|
||
var counter = 0 | ||
|
||
def next = | ||
counter += 1 | ||
counter.toString | ||
|
||
def main(args: Array[String]): Unit = | ||
//List.apply is subject to an optimisation in cleanup | ||
//ensure that the arguments are evaluated in the currect order | ||
// Rewritten to: | ||
// val myList: List = new collection.immutable.::(Test.this.next(), new collection.immutable.::(Test.this.next(), new collection.immutable.::(Test.this.next(), scala.collection.immutable.Nil))); | ||
val myList = List(next, next, next) | ||
assert(myList == List("1", "2", "3"), myList) | ||
|
||
val mySeq = Seq(next, next, next) | ||
assert(mySeq == Seq("4", "5", "6"), mySeq) | ||
|
||
val emptyList = List[Int]() | ||
assert(emptyList == Nil) |