joinTo/joinToString: Do not call toString on elements that are already CharSequence or Char.
#KT-15557
This commit is contained in:
@@ -12241,10 +12241,7 @@ public fun <T, A : Appendable> Array<out T>.joinTo(buffer: A, separator: CharSeq
|
||||
for (element in this) {
|
||||
if (++count > 1) buffer.append(separator)
|
||||
if (limit < 0 || count <= limit) {
|
||||
if (transform != null)
|
||||
buffer.append(transform(element))
|
||||
else
|
||||
buffer.append(if (element == null) "null" else element.toString())
|
||||
buffer.appendElement(element, transform)
|
||||
} else break
|
||||
}
|
||||
if (limit >= 0 && count > limit) buffer.append(truncated)
|
||||
@@ -12428,7 +12425,7 @@ public fun <A : Appendable> CharArray.joinTo(buffer: A, separator: CharSequence
|
||||
if (transform != null)
|
||||
buffer.append(transform(element))
|
||||
else
|
||||
buffer.append(element.toString())
|
||||
buffer.append(element)
|
||||
} else break
|
||||
}
|
||||
if (limit >= 0 && count > limit) buffer.append(truncated)
|
||||
|
||||
@@ -2011,10 +2011,7 @@ public fun <T, A : Appendable> Iterable<T>.joinTo(buffer: A, separator: CharSequ
|
||||
for (element in this) {
|
||||
if (++count > 1) buffer.append(separator)
|
||||
if (limit < 0 || count <= limit) {
|
||||
if (transform != null)
|
||||
buffer.append(transform(element))
|
||||
else
|
||||
buffer.append(if (element == null) "null" else element.toString())
|
||||
buffer.appendElement(element, transform)
|
||||
} else break
|
||||
}
|
||||
if (limit >= 0 && count > limit) buffer.append(truncated)
|
||||
|
||||
@@ -1290,10 +1290,7 @@ public fun <T, A : Appendable> Sequence<T>.joinTo(buffer: A, separator: CharSequ
|
||||
for (element in this) {
|
||||
if (++count > 1) buffer.append(separator)
|
||||
if (limit < 0 || count <= limit) {
|
||||
if (transform != null)
|
||||
buffer.append(transform(element))
|
||||
else
|
||||
buffer.append(if (element == null) "null" else element.toString())
|
||||
buffer.appendElement(element, transform)
|
||||
} else break
|
||||
}
|
||||
if (limit >= 0 && count > limit) buffer.append(truncated)
|
||||
|
||||
@@ -53,3 +53,13 @@ public fun StringBuilder.append(vararg value: Any?): StringBuilder {
|
||||
@kotlin.jvm.JvmVersion
|
||||
@kotlin.internal.InlineOnly
|
||||
public inline operator fun StringBuilder.set(index: Int, value: Char): Unit = this.setCharAt(index, value)
|
||||
|
||||
|
||||
internal fun <T> Appendable.appendElement(element: T, transform: ((T) -> CharSequence)?) {
|
||||
when {
|
||||
transform != null -> append(transform(element))
|
||||
element is CharSequence? -> append(element)
|
||||
element is Char -> append(element)
|
||||
else -> append(element.toString())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user