Skip to content

Commit

Permalink
perf: ⚡️ avoid using non-random-accessed list structure
Browse files Browse the repository at this point in the history
  • Loading branch information
Xanonymous-GitHub committed Aug 17, 2024
1 parent 14eea96 commit 1b0e74e
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions core/src/main/kotlin/tw/xcc/gumtree/model/BasicTree.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import tw.xcc.gumtree.api.tree.Tree
import tw.xcc.gumtree.helper.postOrderOf
import tw.xcc.gumtree.helper.preOrderOf
import java.io.Serializable
import java.util.LinkedList
import java.util.UUID
import java.util.concurrent.atomic.AtomicReference

Expand All @@ -17,7 +16,7 @@ abstract class BasicTree<T> : Serializable, Tree, Traversable<T> where T : Basic

protected val parent = AtomicReference<T?>()

protected val childrenList = AtomicReference(LinkedList<T>())
protected val childrenList = AtomicReference(mutableListOf<T>())

protected val idRef = AtomicReference(UUID.randomUUID().toString())
override val id: String
Expand Down Expand Up @@ -73,7 +72,7 @@ abstract class BasicTree<T> : Serializable, Tree, Traversable<T> where T : Basic
protected fun setChildrenToImpl(children: List<T>) =
with(childrenList) {
synchronized(this) {
val newChildrenList = LinkedList<T>()
val newChildrenList = mutableListOf<T>()
newChildrenList.addAll(children)
newChildrenList.forEach { it.setParentTo(self) }
this.set(newChildrenList)
Expand Down

0 comments on commit 1b0e74e

Please sign in to comment.