Skip to content

Commit

Permalink
Merge pull request #1421 from square/jw.reduce-allocations.2024-02-05
Browse files Browse the repository at this point in the history
Reduce intermediate allocations when create `Options`
  • Loading branch information
JakeWharton authored Feb 5, 2024
2 parents 8b54035 + a88cd34 commit 13e2f46
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion okio/src/commonMain/kotlin/okio/Options.kt
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class Options private constructor(
// indexes to the caller's indexes.
val list = byteStrings.toMutableList()
list.sort()
val indexes = mutableListOf(*byteStrings.map { -1 }.toTypedArray())
val indexes = MutableList(list.size) { -1 }
byteStrings.forEachIndexed { callerIndex, byteString ->
val sortedIndex = list.binarySearch(byteString)
indexes[sortedIndex] = callerIndex
Expand Down

0 comments on commit 13e2f46

Please sign in to comment.