Skip to content

Commit

Permalink
Use SparseList.addRange and removeRange (#1962)
Browse files Browse the repository at this point in the history
These are potentially significantly more efficient than
item-by-item updates, because they take advantage of the
sparseness of the list.
  • Loading branch information
squarejesse authored Apr 11, 2024
1 parent 04d4182 commit 1a4976d
Showing 1 changed file with 6 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -294,14 +294,13 @@ public abstract class LazyListUpdateProcessor<V : Any, W : Any> {
if (loadedItems.size != 0) return

if (splitIndex < itemsBefore.size) {
// TODO(jwilson): add an efficient transferRange function on SparseList.
for (i in itemsBefore.size - 1 downTo splitIndex) {
itemsAfter.add(0, itemsBefore.removeLast())
}
val count = itemsBefore.size - splitIndex
itemsAfter.addRange(0, itemsBefore, splitIndex, count)
itemsBefore.removeRange(splitIndex, splitIndex + count)
} else if (splitIndex > itemsBefore.size) {
for (i in itemsBefore.size until splitIndex) {
itemsBefore.add(itemsAfter.removeAt(0))
}
val count = splitIndex - itemsBefore.size
itemsBefore.addRange(itemsBefore.size, itemsAfter, 0, count)
itemsAfter.removeRange(0, count)
}
}

Expand Down

0 comments on commit 1a4976d

Please sign in to comment.