Skip to content

Commit

Permalink
Avoid intermediary List after transformation + toTypedArray
Browse files Browse the repository at this point in the history
  • Loading branch information
freya022 committed Feb 18, 2025
1 parent eaf741e commit 201124d
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,8 @@ inline fun <T, R, C : MutableCollection<in R>> Iterable<T>.flatMapTo(destination
inline fun <T, reified R> Collection<T>.mapToArray(transform: (T) -> R): Array<R> {
val iterator = iterator()
return Array(size) { _ -> transform(iterator.next()) }
}

inline fun <T, reified R> Array<T>.mapToArray(transform: (T) -> R): Array<R> {
return Array(size) { i -> transform(this[i]) }
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package io.github.freya022.botcommands.api.localization

import io.github.freya022.botcommands.api.core.utils.mapToArray

/**
* Represents an entire localizable string, with parameters.
*
Expand All @@ -18,4 +20,4 @@ interface LocalizationTemplate {
* Processes the localization template and replaces the named parameters by their values
*/
fun LocalizationTemplate.localize(vararg args: Pair<String, Any>): String =
localize(*args.map { (k, v) -> Localization.Entry.entry(k, v) }.toTypedArray())
localize(*args.mapToArray { (k, v) -> Localization.Entry.entry(k, v) })
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@ import io.github.freya022.botcommands.api.core.annotations.BEventListener.RunMod
import io.github.freya022.botcommands.api.core.config.BAppEmojisConfig
import io.github.freya022.botcommands.api.core.events.PreFirstGatewayConnectEvent
import io.github.freya022.botcommands.api.core.service.annotations.BService
import io.github.freya022.botcommands.api.core.utils.findAnnotationRecursive
import io.github.freya022.botcommands.api.core.utils.joinAsList
import io.github.freya022.botcommands.api.core.utils.shortQualifiedName
import io.github.freya022.botcommands.api.core.utils.simpleNestedName
import io.github.freya022.botcommands.api.core.utils.*
import io.github.freya022.botcommands.api.emojis.AppEmojisRegistry
import io.github.freya022.botcommands.api.emojis.annotations.AppEmoji
import io.github.freya022.botcommands.api.emojis.annotations.AppEmojiContainer
Expand Down Expand Up @@ -219,7 +216,7 @@ internal class AppEmojisLoader internal constructor(
private inline fun withScannedResources(packages: Collection<String>, action: (ScanResult) -> Unit) {
ClassGraph()
.acceptPackagesNonRecursive(*packages.toTypedArray())
.acceptClasspathElementsContainingResourcePath(*packages.map { "$it/*" }.toTypedArray())
.acceptClasspathElementsContainingResourcePath(*packages.mapToArray { "$it/*" })
.scan()
.use(action)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ private class ReflectionMetadataScanner private constructor(
"io.github.freya022.botcommands.internal",
*packages.toTypedArray()
)
.acceptClasses(*classes.map { it.name }.toTypedArray())
.acceptClasses(*classes.mapToArray { it.name })
.enableClassInfo()
.enableMethodInfo()
.enableAnnotationInfo()
Expand Down

0 comments on commit 201124d

Please sign in to comment.