diff options
author | Paul Phillips <paulp@improving.org> | 2012-11-05 12:10:30 -0800 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2012-11-05 12:10:30 -0800 |
commit | 757a3a738cbb373f8f10fdc1f01e9ab6176a7076 (patch) | |
tree | 4ebbc8cd4163c7ec470cec0940d33d0812fd312f /src/compiler | |
parent | 3d248efcc1925acb7f73b2b2db2184f8d33b68ad (diff) | |
parent | 092345a24c22a821204fb358d33272ae8f7353be (diff) | |
download | scala-757a3a738cbb373f8f10fdc1f01e9ab6176a7076.tar.gz scala-757a3a738cbb373f8f10fdc1f01e9ab6176a7076.tar.bz2 scala-757a3a738cbb373f8f10fdc1f01e9ab6176a7076.zip |
Merge pull request #1568 from retronym/ticket/6611
SI-6611 Tighten up an unsafe array optimization
Diffstat (limited to 'src/compiler')
-rw-r--r-- | src/compiler/scala/tools/nsc/transform/CleanUp.scala | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/src/compiler/scala/tools/nsc/transform/CleanUp.scala b/src/compiler/scala/tools/nsc/transform/CleanUp.scala index 2e504af47f..3b74cb1168 100644 --- a/src/compiler/scala/tools/nsc/transform/CleanUp.scala +++ b/src/compiler/scala/tools/nsc/transform/CleanUp.scala @@ -15,6 +15,7 @@ abstract class CleanUp extends Transform with ast.TreeDSL { import global._ import definitions._ import CODE._ + import treeInfo.StripCast /** the following two members override abstract members in Transform */ val phaseName: String = "cleanup" @@ -618,14 +619,16 @@ abstract class CleanUp extends Transform with ast.TreeDSL { } transformApply - // This transform replaces Array(Predef.wrapArray(Array(...)), <tag>) - // with just Array(...) - case Apply(appMeth, List(Apply(wrapRefArrayMeth, List(array)), _)) - if (wrapRefArrayMeth.symbol == Predef_wrapRefArray && - appMeth.symbol == ArrayModule_overloadedApply.suchThat { - _.tpe.resultType.dealias.typeSymbol == ObjectClass - }) => - super.transform(array) + // Replaces `Array(Predef.wrapArray(ArrayValue(...).$asInstanceOf[...]), <tag>)` + // with just `ArrayValue(...).$asInstanceOf[...]` + // + // See SI-6611; we must *only* do this for literal vararg arrays. + case Apply(appMeth, List(Apply(wrapRefArrayMeth, List(arg @ StripCast(ArrayValue(_, _)))), _)) + if wrapRefArrayMeth.symbol == Predef_wrapRefArray && appMeth.symbol == ArrayModule_genericApply => + super.transform(arg) + case Apply(appMeth, List(elem0, Apply(wrapArrayMeth, List(rest @ ArrayValue(elemtpt, _))))) + if wrapArrayMeth.symbol == Predef_wrapArray(elemtpt.tpe) && appMeth.symbol == ArrayModule_apply(elemtpt.tpe) => + super.transform(rest.copy(elems = elem0 :: rest.elems)) case _ => super.transform(tree) |