Skip to content

Commit b11f17b

Browse files
authored
Remove Kotlin/JS IR default parameter workarounds. (#1786)
1 parent b35f473 commit b11f17b

6 files changed

Lines changed: 6 additions & 37 deletions

File tree

okio/src/commonMain/kotlin/okio/Buffer.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,9 @@ expect class Buffer() : BufferedSource, BufferedSink {
103103
/** Returns an immutable copy of the first `byteCount` bytes of this buffer as a byte string. */
104104
fun snapshot(byteCount: Int): ByteString
105105

106-
fun readUnsafe(unsafeCursor: UnsafeCursor = DEFAULT__new_UnsafeCursor): UnsafeCursor
106+
fun readUnsafe(unsafeCursor: UnsafeCursor = UnsafeCursor()): UnsafeCursor
107107

108-
fun readAndWriteUnsafe(unsafeCursor: UnsafeCursor = DEFAULT__new_UnsafeCursor): UnsafeCursor
108+
fun readAndWriteUnsafe(unsafeCursor: UnsafeCursor = UnsafeCursor()): UnsafeCursor
109109

110110
override val buffer: Buffer
111111
override fun close()

okio/src/commonMain/kotlin/okio/ByteString.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ internal constructor(data: ByteArray) : Comparable<ByteString> {
9797
* `beginIndex` and ends at the specified `endIndex`. Returns this byte string if `beginIndex` is
9898
* 0 and `endIndex` is the length of this byte string.
9999
*/
100-
fun substring(beginIndex: Int = 0, endIndex: Int = DEFAULT__ByteString_size): ByteString
100+
fun substring(beginIndex: Int = 0, endIndex: Int = size): ByteString
101101

102102
/**
103103
* Returns a byte string equal to this byte string, but with the bytes 'a' through 'z' replaced
@@ -164,9 +164,9 @@ internal constructor(data: ByteArray) : Comparable<ByteString> {
164164
@JvmOverloads
165165
fun indexOf(other: ByteArray, fromIndex: Int = 0): Int
166166

167-
fun lastIndexOf(other: ByteString, fromIndex: Int = DEFAULT__ByteString_size): Int
167+
fun lastIndexOf(other: ByteString, fromIndex: Int = size): Int
168168

169-
fun lastIndexOf(other: ByteArray, fromIndex: Int = DEFAULT__ByteString_size): Int
169+
fun lastIndexOf(other: ByteArray, fromIndex: Int = size): Int
170170

171171
override fun equals(other: Any?): Boolean
172172

@@ -193,7 +193,7 @@ internal constructor(data: ByteArray) : Comparable<ByteString> {
193193
* starting at `offset`.
194194
*/
195195
@JvmStatic
196-
fun ByteArray.toByteString(offset: Int = 0, byteCount: Int = DEFAULT__ByteString_size): ByteString
196+
fun ByteArray.toByteString(offset: Int = 0, byteCount: Int = size): ByteString
197197

198198
/** Returns a new byte string containing the `UTF-8` bytes of this [String]. */
199199
@JvmStatic

okio/src/commonMain/kotlin/okio/Util.kt

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -162,25 +162,3 @@ internal fun Long.toHexString(): String {
162162

163163
return result.concatToString(i, result.size)
164164
}
165-
166-
// Work around a problem where Kotlin/JS IR can't handle default parameters on expect functions
167-
// that depend on the receiver. We use well-known, otherwise-impossible values here and must check
168-
// for them in the receiving function, then swap in the true default value.
169-
// https://youtrack.jetbrains.com/issue/KT-45542
170-
171-
internal val DEFAULT__new_UnsafeCursor = Buffer.UnsafeCursor()
172-
internal fun resolveDefaultParameter(unsafeCursor: Buffer.UnsafeCursor): Buffer.UnsafeCursor {
173-
if (unsafeCursor === DEFAULT__new_UnsafeCursor) return Buffer.UnsafeCursor()
174-
return unsafeCursor
175-
}
176-
177-
internal val DEFAULT__ByteString_size = -1234567890
178-
internal fun ByteString.resolveDefaultParameter(position: Int): Int {
179-
if (position == DEFAULT__ByteString_size) return size
180-
return position
181-
}
182-
183-
internal fun ByteArray.resolveDefaultParameter(sizeParam: Int): Int {
184-
if (sizeParam == DEFAULT__ByteString_size) return size
185-
return sizeParam
186-
}

okio/src/commonMain/kotlin/okio/internal/Buffer.kt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ import okio.and
3737
import okio.asUtf8ToByteArray
3838
import okio.checkOffsetAndCount
3939
import okio.minOf
40-
import okio.resolveDefaultParameter
4140
import okio.toHexString
4241

4342
internal val HEX_DIGIT_BYTES = "0123456789abcdef".asUtf8ToByteArray()
@@ -1528,7 +1527,6 @@ internal inline fun Buffer.commonSnapshot(byteCount: Int): ByteString {
15281527
}
15291528

15301529
internal fun Buffer.commonReadUnsafe(unsafeCursor: UnsafeCursor): UnsafeCursor {
1531-
val unsafeCursor = resolveDefaultParameter(unsafeCursor)
15321530
check(unsafeCursor.buffer == null) { "already attached to a buffer" }
15331531

15341532
unsafeCursor.buffer = this
@@ -1537,7 +1535,6 @@ internal fun Buffer.commonReadUnsafe(unsafeCursor: UnsafeCursor): UnsafeCursor {
15371535
}
15381536

15391537
internal fun Buffer.commonReadAndWriteUnsafe(unsafeCursor: UnsafeCursor): UnsafeCursor {
1540-
val unsafeCursor = resolveDefaultParameter(unsafeCursor)
15411538
check(unsafeCursor.buffer == null) { "already attached to a buffer" }
15421539

15431540
unsafeCursor.buffer = this

okio/src/commonMain/kotlin/okio/internal/ByteString.kt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ import okio.decodeBase64ToArray
3030
import okio.encodeBase64
3131
import okio.isIsoControl
3232
import okio.processUtf8CodePoints
33-
import okio.resolveDefaultParameter
3433
import okio.shr
3534
import okio.toUtf8String
3635

@@ -126,7 +125,6 @@ internal inline fun ByteString.commonToAsciiUppercase(): ByteString {
126125

127126
@Suppress("NOTHING_TO_INLINE")
128127
internal inline fun ByteString.commonSubstring(beginIndex: Int, endIndex: Int): ByteString {
129-
val endIndex = resolveDefaultParameter(endIndex)
130128
require(beginIndex >= 0) { "beginIndex < 0" }
131129
require(endIndex <= data.size) { "endIndex > length(${data.size})" }
132130

@@ -218,7 +216,6 @@ internal inline fun ByteString.commonLastIndexOf(
218216

219217
@Suppress("NOTHING_TO_INLINE")
220218
internal inline fun ByteString.commonLastIndexOf(other: ByteArray, fromIndex: Int): Int {
221-
val fromIndex = resolveDefaultParameter(fromIndex)
222219
val limit = data.size - other.size
223220
for (i in minOf(fromIndex, limit) downTo 0) {
224221
if (arrayRangeEquals(data, i, other, 0, other.size)) {
@@ -270,7 +267,6 @@ internal inline fun commonOf(data: ByteArray) = ByteString(data.copyOf())
270267

271268
@Suppress("NOTHING_TO_INLINE")
272269
internal inline fun ByteArray.commonToByteString(offset: Int, byteCount: Int): ByteString {
273-
val byteCount = resolveDefaultParameter(byteCount)
274270
checkOffsetAndCount(size.toLong(), offset.toLong(), byteCount.toLong())
275271
return ByteString(copyOfRange(offset, offset + byteCount))
276272
}

okio/src/commonMain/kotlin/okio/internal/SegmentedByteString.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ import okio.Segment
2828
import okio.SegmentedByteString
2929
import okio.arrayRangeEquals
3030
import okio.checkOffsetAndCount
31-
import okio.resolveDefaultParameter
3231

3332
internal fun IntArray.binarySearch(value: Int, fromIndex: Int, toIndex: Int): Int {
3433
var left = fromIndex
@@ -101,7 +100,6 @@ private inline fun SegmentedByteString.forEachSegment(
101100
// have to call these functions. Remove all this nonsense when expect class allow actual code.
102101

103102
internal inline fun SegmentedByteString.commonSubstring(beginIndex: Int, endIndex: Int): ByteString {
104-
val endIndex = resolveDefaultParameter(endIndex)
105103
require(beginIndex >= 0) { "beginIndex=$beginIndex < 0" }
106104
require(endIndex <= size) { "endIndex=$endIndex > length($size)" }
107105

0 commit comments

Comments
 (0)