probablyParallelStream
This commit is contained in:
parent
a757fcc9ab
commit
71fc9601b0
@ -25,6 +25,15 @@ import ru.dbotthepony.mc.otm.core.integerDivisionUp
|
||||
import ru.dbotthepony.mc.otm.core.registryName
|
||||
import ru.dbotthepony.mc.otm.core.set
|
||||
import ru.dbotthepony.mc.otm.data.stream
|
||||
import java.util.stream.Stream
|
||||
|
||||
private fun <T> Collection<T>.probablyParallelStream(): Stream<out T> {
|
||||
if (size >= 400) {
|
||||
return parallelStream()
|
||||
}
|
||||
|
||||
return stream()
|
||||
}
|
||||
|
||||
object MatterManager : SimpleJsonResourceReloadListener(GsonBuilder().setPrettyPrinting().disableHtmlEscaping().create(), "otm_matter") {
|
||||
const val DIRECTORY = "otm_matter"
|
||||
@ -222,7 +231,7 @@ object MatterManager : SimpleJsonResourceReloadListener(GsonBuilder().setPrettyP
|
||||
if (key != null) {
|
||||
if (replaceIfExists) {
|
||||
// search & replace in parallel, if possible
|
||||
val replaced = registry.parallelStream().anyMatch {
|
||||
val replaced = registry.probablyParallelStream().anyMatch {
|
||||
if (it is MutableKeyEntry && it.key == key) {
|
||||
if (!comparePriority || it.priority < priority!!) {
|
||||
it.matter = matter
|
||||
@ -242,7 +251,7 @@ object MatterManager : SimpleJsonResourceReloadListener(GsonBuilder().setPrettyP
|
||||
registry.add(MutableKeyEntry(key, mutableListOf(modifier), matter, complexity, priority ?: 0))
|
||||
}
|
||||
} else {
|
||||
if (registry.parallelStream().anyMatch { it is MutableKeyEntry && it.key == key }) {
|
||||
if (registry.probablyParallelStream().anyMatch { it is MutableKeyEntry && it.key == key }) {
|
||||
fail { "Value with key $key already exists" }
|
||||
return
|
||||
}
|
||||
@ -252,7 +261,7 @@ object MatterManager : SimpleJsonResourceReloadListener(GsonBuilder().setPrettyP
|
||||
} else {
|
||||
if (replaceIfExists) {
|
||||
// search & replace in parallel, if possible
|
||||
val replaced = registry.parallelStream().anyMatch {
|
||||
val replaced = registry.probablyParallelStream().anyMatch {
|
||||
if (it is MutableTagEntry && it.tag == tag) {
|
||||
if (!comparePriority || it.priority < priority!!) {
|
||||
it.matter = matter
|
||||
@ -272,7 +281,7 @@ object MatterManager : SimpleJsonResourceReloadListener(GsonBuilder().setPrettyP
|
||||
registry.add(MutableTagEntry(tag!!, mutableListOf(modifier), matter, complexity, priority ?: 0))
|
||||
}
|
||||
} else {
|
||||
if (registry.parallelStream().anyMatch { it is MutableTagEntry && it.tag == tag }) {
|
||||
if (registry.probablyParallelStream().anyMatch { it is MutableTagEntry && it.tag == tag }) {
|
||||
fail { "Value with tag $tag already exists" }
|
||||
return
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user