Skip to content

Commit f07236b

Browse files
committed
Optimize central unwrap implementations.
The default implementation of `Unwrappable.unwrap` creates a `Sequence` that is almost never necessary (but it is at least fail-safe so I think we should keep it). Here we provide improved implementations for `Wrapper` and `BackStackScreen`.
1 parent f8c9e8c commit f07236b

File tree

3 files changed

+6
-0
lines changed

3 files changed

+6
-0
lines changed

workflow-ui/core-common/src/main/java/com/squareup/workflow1/ui/Container.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ public interface Container<CategoryT, out C : CategoryT> : Composite<C> {
8787
public interface Wrapper<BaseT : Any, out C : BaseT> : Container<BaseT, C>, Compatible {
8888
public val content: C
8989

90+
override val unwrapped: Any get() = content
91+
9092
/**
9193
* Default implementation makes this [Wrapper] compatible with others of the same type,
9294
* and which wrap compatible [content].

workflow-ui/core-common/src/main/java/com/squareup/workflow1/ui/navigation/BackStackScreen.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ public class BackStackScreen<out StackedT : Screen> internal constructor(
4848

4949
override val compatibilityKey: String = keyFor(this, name)
5050

51+
override val unwrapped: Any get() = top
52+
5153
override fun asSequence(): Sequence<StackedT> = frames.asSequence()
5254

5355
/**

workflow-ui/core-common/src/main/java/com/squareup/workflow1/ui/navigation/BodyAndOverlaysScreen.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ public class BodyAndOverlaysScreen<B : Screen, O : Overlay>(
7979
) : Screen, Compatible, Composite<Any> {
8080
override val compatibilityKey: String = keyFor(this, name)
8181

82+
override val unwrapped: Any = overlays.lastOrNull() ?: body
83+
8284
override fun asSequence(): Sequence<Any> = sequenceOf(body) + overlays.asSequence()
8385

8486
public fun <S : Screen> mapBody(transform: (B) -> S): BodyAndOverlaysScreen<S, O> {

0 commit comments

Comments
 (0)