Skip to content

Commit

Permalink
Refactor of common path to return a list (#2466)
Browse files Browse the repository at this point in the history
Found in my stash list...
  • Loading branch information
JakeWharton authored Nov 20, 2024
1 parent 717bb60 commit 9426a4d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ public abstract class GuestProtocolAdapter(
public abstract fun removeWidget(id: Id)

@RedwoodCodegenApi
public val childrenVisitor: ProtocolWidget.ChildrenVisitor = if (synthesizeSubtreeRemoval) {
public val childrenRemover: ProtocolWidget.ChildrenVisitor = if (synthesizeSubtreeRemoval) {
object : ProtocolWidget.ChildrenVisitor {
override fun visit(
parent: ProtocolWidget,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,25 +37,26 @@ public class ProtocolWidgetChildren(
}

override fun remove(index: Int, count: Int) {
if (guestAdapter.synthesizeSubtreeRemoval) {
val removedIds = if (guestAdapter.synthesizeSubtreeRemoval) {
// This boxes Id values. Don't bother optimizing since it only serves very old hosts.
val removedIds = ArrayList<Id>(count)
for (i in index until index + count) {
val widget = _widgets[i]
removedIds += widget.id
guestAdapter.removeWidget(widget.id)
buildList(count) {
for (i in index until index + count) {
val widget = _widgets[i]
this += widget.id
guestAdapter.removeWidget(widget.id)

widget.depthFirstWalk(guestAdapter.childrenVisitor)
widget.depthFirstWalk(guestAdapter.childrenRemover)
}
}
guestAdapter.appendRemove(id, tag, index, count, removedIds)
} else {
for (i in index until index + count) {
val widget = _widgets[i]
guestAdapter.removeWidget(widget.id)
widget.depthFirstWalk(guestAdapter.childrenVisitor)
widget.depthFirstWalk(guestAdapter.childrenRemover)
}
guestAdapter.appendRemove(id, tag, index, count, emptyList())
emptyList()
}
guestAdapter.appendRemove(id, tag, index, count, removedIds)

_widgets.remove(index, count)
}
Expand Down

0 comments on commit 9426a4d

Please sign in to comment.