[K/N] Fix StringBuilder.setRange capacity expansion

This commit is contained in:
Abduqodiri Qurbonzoda
2023-06-06 17:43:19 +03:00
committed by Space Team
parent 21636efe38
commit d8cfc79d92
@@ -435,7 +435,7 @@ actual class StringBuilder private constructor (
val coercedEndIndex = endIndex.coerceAtMost(_length)
val lengthDiff = value.length - (coercedEndIndex - startIndex)
ensureExtraCapacity(_length + lengthDiff)
ensureExtraCapacity(lengthDiff)
array.copyInto(array, startIndex = coercedEndIndex, endIndex = _length, destinationOffset = startIndex + value.length)
var replaceIndex = startIndex
for (index in 0 until value.length) array[replaceIndex++] = value[index] // optimize