summaryrefslogtreecommitdiff
path: root/src/compiler/scala/tools/nsc/backend/jvm/BCodeIdiomatic.scala
diff options
context:
space:
mode:
authorMarko Elezovic <marko@mentat-labs.com>2015-11-27 03:36:27 +0100
committerLukas Rytz <lukas.rytz@gmail.com>2016-02-06 08:58:16 +0100
commitcb68d9c1868e9fbb3e58cdfd606274e070db5b31 (patch)
tree00d0be1be40db7ca93e2f98f7475058ce53b5757 /src/compiler/scala/tools/nsc/backend/jvm/BCodeIdiomatic.scala
parent93b7e2982d7ee503bfc27a9523d17bbd2f5e1fd6 (diff)
downloadscala-cb68d9c1868e9fbb3e58cdfd606274e070db5b31.tar.gz
scala-cb68d9c1868e9fbb3e58cdfd606274e070db5b31.tar.bz2
scala-cb68d9c1868e9fbb3e58cdfd606274e070db5b31.zip
SI-9571 Avoid boxing primitives in string concatenation
Diffstat (limited to 'src/compiler/scala/tools/nsc/backend/jvm/BCodeIdiomatic.scala')
-rw-r--r--src/compiler/scala/tools/nsc/backend/jvm/BCodeIdiomatic.scala15
1 files changed, 9 insertions, 6 deletions
diff --git a/src/compiler/scala/tools/nsc/backend/jvm/BCodeIdiomatic.scala b/src/compiler/scala/tools/nsc/backend/jvm/BCodeIdiomatic.scala
index 328a8187c8..0a95bc5e39 100644
--- a/src/compiler/scala/tools/nsc/backend/jvm/BCodeIdiomatic.scala
+++ b/src/compiler/scala/tools/nsc/backend/jvm/BCodeIdiomatic.scala
@@ -197,16 +197,19 @@ abstract class BCodeIdiomatic extends SubComponent {
/*
* can-multi-thread
*/
- final def genStringConcat(el: BType, pos: Position): Unit = {
- val jtype = el match {
+ def genConcat(elemType: BType, pos: Position): Unit = {
+ val paramType = elemType match {
case ct: ClassBType if ct.isSubtypeOf(StringRef).get => StringRef
case ct: ClassBType if ct.isSubtypeOf(jlStringBufferRef).get => jlStringBufferRef
case ct: ClassBType if ct.isSubtypeOf(jlCharSequenceRef).get => jlCharSequenceRef
- case rt: RefBType => ObjectRef
- case pt: PrimitiveBType => pt // Currently this ends up being boxed in erasure
+ // Don't match for `ArrayBType(CHAR)`, even though StringBuilder has such an overload:
+ // `"a" + Array('b')` should NOT be "ab", but "a[C@...".
+ case _: RefBType => ObjectRef
+ // jlStringBuilder does not have overloads for byte and short, but we can just use the int version
+ case BYTE | SHORT => INT
+ case pt: PrimitiveBType => pt
}
-
- val bt = MethodBType(List(jtype), jlStringBuilderRef)
+ val bt = MethodBType(List(paramType), jlStringBuilderRef)
invokevirtual(JavaStringBuilderClassName, "append", bt.descriptor, pos)
}