Skip to content

Commit 378a2fe

Browse files
s5bugSirius902
andcommitted
Replace Vec with asymptotically efficient immutable Vector
Co-authored-by: Sirius902 <10891979+Sirius902@users.noreply.github.com>
1 parent 3c25474 commit 378a2fe

File tree

4 files changed

+3394
-330
lines changed

4 files changed

+3394
-330
lines changed

Common/src/main/java/at/petrak/hexcasting/api/casting/eval/vm/FrameForEach.kt

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import at.petrak.hexcasting.api.utils.NBTBuilder
99
import at.petrak.hexcasting.api.utils.getList
1010
import at.petrak.hexcasting.api.utils.hasList
1111
import at.petrak.hexcasting.api.utils.serializeToNBT
12-
import at.petrak.hexcasting.api.utils.Vec
12+
import at.petrak.hexcasting.api.utils.Vector
1313
import at.petrak.hexcasting.common.lib.hex.HexEvalSounds
1414
import at.petrak.hexcasting.common.lib.hex.HexIotaTypes
1515
import net.minecraft.nbt.CompoundTag
@@ -29,13 +29,12 @@ data class FrameForEach(
2929
val data: SpellList,
3030
val code: SpellList,
3131
val baseStack: List<Iota>?,
32-
val acc: Vec<Iota>
32+
val acc: Vector<Iota>
3333
) : ContinuationFrame {
3434

3535
/** When halting, we add the stack state at halt to the stack accumulator, then return the original pre-Thoth stack, plus the accumulator. */
3636
override fun breakDownwards(stack: List<Iota>): Pair<Boolean, List<Iota>> {
37-
val newStack = baseStack?.toMutableList() ?: mutableListOf()
38-
newStack.add(ListIota(acc.appendAll(stack).toList()))
37+
val newStack = Vector.from(stack).appendedAll(acc)
3938
return true to newStack
4039
}
4140

@@ -51,7 +50,7 @@ data class FrameForEach(
5150
harness.image.stack.toList() to acc
5251
} else {
5352
// else save the stack to the accumulator and reuse the saved base stack.
54-
baseStack to acc.appendAll(harness.image.stack)
53+
baseStack to acc.appendedAll(harness.image.stack)
5554
}
5655

5756
// If we still have data to process...
@@ -65,7 +64,7 @@ data class FrameForEach(
6564
Triple(data.car, harness.image.withUsedOp(), cont2)
6665
} else {
6766
// Else, dump our final list onto the stack.
68-
Triple(ListIota(acc.toList()), harness.image, continuation)
67+
Triple(ListIota(nextAcc), harness.image, continuation)
6968
}
7069
val tStack = stack.toMutableList()
7170
tStack.add(stackTop)
@@ -88,7 +87,7 @@ data class FrameForEach(
8887
"accumulator" %= acc.toList().serializeToNBT()
8988
}
9089

91-
override fun size() = data.size() + code.size() + acc.length + (baseStack?.size ?: 0)
90+
override fun size() = data.size() + code.size() + acc.size + (baseStack?.size ?: 0)
9291

9392
override val type: ContinuationFrame.Type<*> = TYPE
9493

@@ -103,10 +102,10 @@ data class FrameForEach(
103102
HexIotaTypes.LIST.deserialize(tag.getList("base", Tag.TAG_COMPOUND), world)!!.list.toList()
104103
else
105104
null,
106-
Vec.ofIterable(HexIotaTypes.LIST.deserialize(
105+
Vector.from(HexIotaTypes.LIST.deserialize(
107106
tag.getList("accumulator", Tag.TAG_COMPOUND),
108107
world
109-
)!!.list)
108+
)!!.list.toList())
110109
)
111110
}
112111

Common/src/main/java/at/petrak/hexcasting/api/utils/Vec.java

Lines changed: 0 additions & 319 deletions
This file was deleted.

0 commit comments

Comments
 (0)