Skip to content

Commit

Permalink
Merge pull request #1143 from k163377/fix-1139
Browse files Browse the repository at this point in the history
Reduce the use of spread operator to improve performance
  • Loading branch information
Raibaz committed Sep 18, 2023
2 parents 5a811c7 + e45af83 commit f131526
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 36 deletions.
40 changes: 20 additions & 20 deletions modules/mockk-dsl/src/commonMain/kotlin/io/mockk/API.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ object MockKDsl {
inline fun <reified T : Any> internalMockk(
name: String? = null,
relaxed: Boolean = false,
vararg moreInterfaces: KClass<*>,
moreInterfaces: Array<out KClass<*>>,
relaxUnitFun: Boolean = false,
block: T.() -> Unit = {}
): T {
Expand All @@ -47,7 +47,7 @@ object MockKDsl {
inline fun <T : Any> internalSpyk(
objToCopy: T,
name: String? = null,
vararg moreInterfaces: KClass<*>,
moreInterfaces: Array<out KClass<*>>,
recordPrivateCalls: Boolean = false,
block: T.() -> Unit = {}
): T {
Expand All @@ -67,7 +67,7 @@ object MockKDsl {
*/
inline fun <reified T : Any> internalSpyk(
name: String? = null,
vararg moreInterfaces: KClass<*>,
moreInterfaces: Array<out KClass<*>>,
recordPrivateCalls: Boolean = false,
block: T.() -> Unit = {}
): T {
Expand Down Expand Up @@ -269,7 +269,7 @@ object MockKDsl {
/**
* Checks if all recorded calls were verified.
*/
fun internalConfirmVerified(vararg mocks: Any) {
fun internalConfirmVerified(mocks: Array<out Any>) {
if (mocks.isEmpty()) {
MockKGateway.implementation().verificationAcknowledger.acknowledgeVerified()
}
Expand All @@ -282,7 +282,7 @@ object MockKDsl {
/**
* Checks if all recorded calls are necessary.
*/
fun internalCheckUnnecessaryStub(vararg mocks: Any) {
fun internalCheckUnnecessaryStub(mocks: Array<out Any>) {
if (mocks.isEmpty()) {
MockKGateway.implementation().verificationAcknowledger.checkUnnecessaryStub()
}
Expand All @@ -297,7 +297,7 @@ object MockKDsl {
*/
inline fun internalClearMocks(
firstMock: Any,
vararg mocks: Any,
mocks: Array<out Any>,
answers: Boolean = true,
recordedCalls: Boolean = true,
childMocks: Boolean = true,
Expand Down Expand Up @@ -354,7 +354,7 @@ object MockKDsl {
/**
* Declares static mockk. Deprecated
*/
inline fun internalStaticMockk(vararg kClass: KClass<out Any>) = MockKStaticScope(*kClass)
inline fun internalStaticMockk(kClass: Array<KClass<*>>) = MockKStaticScope(*kClass)

/**
* Declares object mockk. Deprecated
Expand All @@ -378,7 +378,7 @@ object MockKDsl {
type: KClass<T>,
name: String?,
relaxed: Boolean,
vararg moreInterfaces: KClass<*>,
moreInterfaces: Array<out KClass<*>>,
relaxUnitFun: Boolean = false,
block: T.() -> Unit
): T {
Expand Down Expand Up @@ -406,13 +406,13 @@ object MockKDsl {
/**
* Object mockk
*/
inline fun internalMockkObject(vararg objects: Any, recordPrivateCalls: Boolean = false) {
inline fun internalMockkObject(objects: Array<out Any>, recordPrivateCalls: Boolean = false) {
val factory = MockKGateway.implementation().objectMockFactory

objects.forEach {
val cancellation = factory.objectMockk(it, recordPrivateCalls)

internalClearMocks(it)
internalClearMocks(it, emptyArray())

MockKCancellationRegistry
.subRegistry(MockKCancellationRegistry.Type.OBJECT)
Expand All @@ -424,7 +424,7 @@ object MockKDsl {
/**
* Cancel object mocks.
*/
inline fun internalUnmockkObject(vararg objects: Any) {
inline fun internalUnmockkObject(objects: Array<out Any>) {
objects.forEach {
MockKCancellationRegistry
.subRegistry(MockKCancellationRegistry.Type.OBJECT)
Expand All @@ -436,7 +436,7 @@ object MockKDsl {
* Clear object mocks.
*/
inline fun internalClearObjectMockk(
vararg objects: Any,
objects: Array<out Any>,
answers: Boolean = true,
recordedCalls: Boolean = true,
childMocks: Boolean = true,
Expand All @@ -460,13 +460,13 @@ object MockKDsl {
/**
* Static mockk
*/
inline fun internalMockkStatic(vararg classes: KClass<*>) {
inline fun internalMockkStatic(classes: Array<out KClass<*>>) {
val factory = MockKGateway.implementation().staticMockFactory

classes.forEach {
val cancellation = factory.staticMockk(it)

internalClearStaticMockk(it)
internalClearStaticMockk(arrayOf(it))

MockKCancellationRegistry
.subRegistry(MockKCancellationRegistry.Type.STATIC)
Expand All @@ -477,7 +477,7 @@ object MockKDsl {
/**
* Cancel static mocks.
*/
inline fun internalUnmockkStatic(vararg classes: KClass<*>) {
inline fun internalUnmockkStatic(classes: Array<out KClass<*>>) {
classes.forEach {
MockKCancellationRegistry
.subRegistry(MockKCancellationRegistry.Type.STATIC)
Expand All @@ -489,7 +489,7 @@ object MockKDsl {
* Clear static mocks.
*/
inline fun internalClearStaticMockk(
vararg classes: KClass<*>,
classes: Array<out KClass<*>>,
answers: Boolean = true,
recordedCalls: Boolean = true,
childMocks: Boolean = true,
Expand All @@ -514,7 +514,7 @@ object MockKDsl {
* Constructor mockk
*/
inline fun internalMockkConstructor(
vararg classes: KClass<*>,
classes: Array<out KClass<*>>,
recordPrivateCalls: Boolean = false,
localToThread: Boolean = true
) {
Expand All @@ -523,7 +523,7 @@ object MockKDsl {
classes.forEach {
val cancellation = factory.constructorMockk(it, recordPrivateCalls, localToThread)

internalClearConstructorMockk(it)
internalClearConstructorMockk(arrayOf(it))

MockKCancellationRegistry
.subRegistry(MockKCancellationRegistry.Type.CONSTRUCTOR)
Expand All @@ -534,7 +534,7 @@ object MockKDsl {
/**
* Cancel constructor mocks.
*/
inline fun internalUnmockkConstructor(vararg classes: KClass<*>) {
inline fun internalUnmockkConstructor(classes: Array<out KClass<*>>) {
classes.forEach {
MockKGateway.implementation().constructorMockFactory.clear(
it,
Expand All @@ -556,7 +556,7 @@ object MockKDsl {
* Clear constructor mocks.
*/
inline fun internalClearConstructorMockk(
vararg classes: KClass<*>,
classes: Array<out KClass<*>>,
answers: Boolean = true,
recordedCalls: Boolean = true,
childMocks: Boolean = true,
Expand Down
32 changes: 16 additions & 16 deletions modules/mockk/src/commonMain/kotlin/io/mockk/MockK.kt
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ inline fun <reified T : Any> mockk(
MockKDsl.internalMockk(
name,
relaxed,
*moreInterfaces,
moreInterfaces,
relaxUnitFun = relaxUnitFun,
block = block
)
Expand All @@ -67,7 +67,7 @@ inline fun <reified T : Any> spyk(
): T = MockK.useImpl {
MockKDsl.internalSpyk(
name,
*moreInterfaces,
moreInterfaces,
recordPrivateCalls = recordPrivateCalls,
block = block
)
Expand All @@ -94,7 +94,7 @@ inline fun <reified T : Any> spyk(
MockKDsl.internalSpyk(
objToCopy,
name,
*moreInterfaces,
moreInterfaces,
recordPrivateCalls = recordPrivateCalls,
block = block
)
Expand Down Expand Up @@ -390,14 +390,14 @@ fun coExcludeRecords(
* Checks if all recorded calls were verified.
*/
fun confirmVerified(vararg mocks: Any) = MockK.useImpl {
MockKDsl.internalConfirmVerified(*mocks)
MockKDsl.internalConfirmVerified(mocks)
}

/**
* Checks if all recorded calls are necessary.
*/
fun checkUnnecessaryStub(vararg mocks: Any) = MockK.useImpl {
MockKDsl.internalCheckUnnecessaryStub(*mocks)
MockKDsl.internalCheckUnnecessaryStub(mocks)
}

/**
Expand Down Expand Up @@ -457,7 +457,7 @@ inline fun <T : Any> mockkClass(
type,
name,
relaxed,
*moreInterfaces,
moreInterfaces,
relaxUnitFun = relaxUnitFun,
block = block
)
Expand All @@ -479,14 +479,14 @@ inline fun <T : Any> mockkClass(
* @see [unmockkObject] To manually cancel mock
*/
inline fun mockkObject(vararg objects: Any, recordPrivateCalls: Boolean = false) = MockK.useImpl {
MockKDsl.internalMockkObject(*objects, recordPrivateCalls = recordPrivateCalls)
MockKDsl.internalMockkObject(objects, recordPrivateCalls = recordPrivateCalls)
}

/**
* Cancel object mocks.
*/
inline fun unmockkObject(vararg objects: Any) = MockK.useImpl {
MockKDsl.internalUnmockkObject(*objects)
MockKDsl.internalUnmockkObject(objects)
}

/**
Expand All @@ -507,7 +507,7 @@ inline fun mockkObject(vararg objects: Any, recordPrivateCalls: Boolean = false,
* @see [unmockkStatic] To manually cancel mock
*/
inline fun mockkStatic(vararg classes: KClass<*>) = MockK.useImpl {
MockKDsl.internalMockkStatic(*classes)
MockKDsl.internalMockkStatic(classes)
}

/**
Expand All @@ -516,7 +516,7 @@ inline fun mockkStatic(vararg classes: KClass<*>) = MockK.useImpl {
* @see [unmockkStatic] To manually cancel mock
*/
inline fun mockkStatic(vararg classes: String) = MockK.useImpl {
MockKDsl.internalMockkStatic(*classes.map { InternalPlatformDsl.classForName(it) as KClass<*> }.toTypedArray())
MockKDsl.internalMockkStatic(classes.map { InternalPlatformDsl.classForName(it) as KClass<*> }.toTypedArray())
}

/**
Expand All @@ -529,7 +529,7 @@ inline fun clearStaticMockk(
childMocks: Boolean = true
) = MockK.useImpl {
MockKDsl.internalClearStaticMockk(
*classes,
classes,
answers = answers,
recordedCalls = recordedCalls,
childMocks = childMocks
Expand All @@ -540,14 +540,14 @@ inline fun clearStaticMockk(
* Cancel static mocks.
*/
inline fun unmockkStatic(vararg classes: KClass<*>) = MockK.useImpl {
MockKDsl.internalUnmockkStatic(*classes)
MockKDsl.internalUnmockkStatic(classes)
}

/**
* Cancel static mocks.
*/
inline fun unmockkStatic(vararg classes: String) = MockK.useImpl {
MockKDsl.internalUnmockkStatic(*classes.map { InternalPlatformDsl.classForName(it) as KClass<*> }.toTypedArray())
MockKDsl.internalUnmockkStatic(classes.map { InternalPlatformDsl.classForName(it) as KClass<*> }.toTypedArray())
}

/**
Expand Down Expand Up @@ -597,7 +597,7 @@ inline fun mockkConstructor(
localToThread: Boolean = false
) = MockK.useImpl {
MockKDsl.internalMockkConstructor(
*classes,
classes,
recordPrivateCalls = recordPrivateCalls,
localToThread = localToThread
)
Expand All @@ -607,7 +607,7 @@ inline fun mockkConstructor(
* Cancel constructor mocks.
*/
inline fun unmockkConstructor(vararg classes: KClass<*>) = MockK.useImpl {
MockKDsl.internalUnmockkConstructor(*classes)
MockKDsl.internalUnmockkConstructor(classes)
}

/**
Expand Down Expand Up @@ -637,7 +637,7 @@ inline fun clearConstructorMockk(
childMocks: Boolean = true
) = MockK.useImpl {
MockKDsl.internalClearConstructorMockk(
*classes,
classes,
answers = answers,
recordedCalls = recordedCalls,
childMocks = childMocks
Expand Down

0 comments on commit f131526

Please sign in to comment.