Move ModifiedParentDataNode to be an entity of LayoutNodeWrapper

Bug: 181981276

ModifiedParantDataNode is now an entity of LayoutNodeWrapper.
Introduced SimpleEntity to represent simple modifier holding
entities.

Test: Ran ParentDataModifierTest
Change-Id: I54bade84c91a44439af46a263f1841c52f346b6a
diff --git a/compose/ui/ui/src/commonMain/kotlin/androidx/compose/ui/node/DelegatingLayoutNodeWrapper.kt b/compose/ui/ui/src/commonMain/kotlin/androidx/compose/ui/node/DelegatingLayoutNodeWrapper.kt
index 17a1516..b54c1bf 100644
--- a/compose/ui/ui/src/commonMain/kotlin/androidx/compose/ui/node/DelegatingLayoutNodeWrapper.kt
+++ b/compose/ui/ui/src/commonMain/kotlin/androidx/compose/ui/node/DelegatingLayoutNodeWrapper.kt
@@ -145,6 +145,4 @@
     override fun minIntrinsicHeight(width: Int) = wrapped.minIntrinsicHeight(width)
 
     override fun maxIntrinsicHeight(width: Int) = wrapped.maxIntrinsicHeight(width)
-
-    override val parentData: Any? get() = wrapped.parentData
 }
diff --git a/compose/ui/ui/src/commonMain/kotlin/androidx/compose/ui/node/EntityList.kt b/compose/ui/ui/src/commonMain/kotlin/androidx/compose/ui/node/EntityList.kt
index 588d2a9..ac7077d 100644
--- a/compose/ui/ui/src/commonMain/kotlin/androidx/compose/ui/node/EntityList.kt
+++ b/compose/ui/ui/src/commonMain/kotlin/androidx/compose/ui/node/EntityList.kt
@@ -19,6 +19,7 @@
 import androidx.compose.ui.Modifier
 import androidx.compose.ui.draw.DrawModifier
 import androidx.compose.ui.input.pointer.PointerInputModifier
+import androidx.compose.ui.layout.ParentDataModifier
 import androidx.compose.ui.semantics.SemanticsEntity
 import androidx.compose.ui.semantics.SemanticsModifier
 
@@ -46,6 +47,9 @@
         if (modifier is SemanticsModifier) {
             add(SemanticsEntity(layoutNodeWrapper, modifier), SemanticsEntityType.index)
         }
+        if (modifier is ParentDataModifier) {
+            add(SimpleEntity(layoutNodeWrapper, modifier), ParentDataEntityType.index)
+        }
     }
 
     private fun <T : LayoutNodeEntity<T, *>> add(entity: T, index: Int) {
@@ -122,7 +126,9 @@
         val DrawEntityType = EntityType<DrawEntity, DrawModifier>(0)
         val PointerInputEntityType = EntityType<PointerInputEntity, PointerInputModifier>(1)
         val SemanticsEntityType = EntityType<SemanticsEntity, SemanticsModifier>(2)
+        val ParentDataEntityType =
+            EntityType<SimpleEntity<ParentDataModifier>, ParentDataModifier>(3)
 
-        private const val TypeCount = 3
+        private const val TypeCount = 4
     }
 }
diff --git a/compose/ui/ui/src/commonMain/kotlin/androidx/compose/ui/node/InnerPlaceable.kt b/compose/ui/ui/src/commonMain/kotlin/androidx/compose/ui/node/InnerPlaceable.kt
index fdb4ab6..e618264 100644
--- a/compose/ui/ui/src/commonMain/kotlin/androidx/compose/ui/node/InnerPlaceable.kt
+++ b/compose/ui/ui/src/commonMain/kotlin/androidx/compose/ui/node/InnerPlaceable.kt
@@ -57,9 +57,6 @@
         return this
     }
 
-    override val parentData: Any?
-        get() = null
-
     override fun findPreviousFocusWrapper() = wrappedBy?.findPreviousFocusWrapper()
 
     override fun findNextFocusWrapper(excludeDeactivated: Boolean): ModifiedFocusNode? = null
diff --git a/compose/ui/ui/src/commonMain/kotlin/androidx/compose/ui/node/LayoutNode.kt b/compose/ui/ui/src/commonMain/kotlin/androidx/compose/ui/node/LayoutNode.kt
index be57631..dfd645d 100644
--- a/compose/ui/ui/src/commonMain/kotlin/androidx/compose/ui/node/LayoutNode.kt
+++ b/compose/ui/ui/src/commonMain/kotlin/androidx/compose/ui/node/LayoutNode.kt
@@ -45,7 +45,6 @@
 import androidx.compose.ui.layout.OnGloballyPositionedModifier
 import androidx.compose.ui.layout.OnPlacedModifier
 import androidx.compose.ui.layout.OnRemeasuredModifier
-import androidx.compose.ui.layout.ParentDataModifier
 import androidx.compose.ui.layout.Placeable
 import androidx.compose.ui.layout.Remeasurement
 import androidx.compose.ui.layout.RemeasurementModifier
@@ -727,11 +726,6 @@
                         .initialize()
                         .assignChained(toWrap)
                 }
-                if (mod is ParentDataModifier) {
-                    wrapper = ModifiedParentDataNode(wrapper, mod)
-                        .initialize()
-                        .assignChained(toWrap)
-                }
                 if (mod is OnRemeasuredModifier) {
                     wrapper = RemeasureModifierWrapper(wrapper, mod)
                         .initialize()
diff --git a/compose/ui/ui/src/commonMain/kotlin/androidx/compose/ui/node/LayoutNodeWrapper.kt b/compose/ui/ui/src/commonMain/kotlin/androidx/compose/ui/node/LayoutNodeWrapper.kt
index 1d69f8e..b31d3dd 100644
--- a/compose/ui/ui/src/commonMain/kotlin/androidx/compose/ui/node/LayoutNodeWrapper.kt
+++ b/compose/ui/ui/src/commonMain/kotlin/androidx/compose/ui/node/LayoutNodeWrapper.kt
@@ -40,6 +40,7 @@
 import androidx.compose.ui.layout.Measurable
 import androidx.compose.ui.layout.MeasureResult
 import androidx.compose.ui.layout.MeasureScope
+import androidx.compose.ui.layout.ParentDataModifier
 import androidx.compose.ui.layout.Placeable
 import androidx.compose.ui.layout.VerticalAlignmentLine
 import androidx.compose.ui.layout.findRoot
@@ -166,6 +167,22 @@
     var zIndex: Float = 0f
         protected set
 
+    override val parentData: Any?
+        get() = entities.head(EntityList.ParentDataEntityType).parentData
+
+    private val SimpleEntity<ParentDataModifier>?.parentData: Any?
+        get() = if (this == null) {
+            wrapped?.parentData
+        } else {
+            with(modifier) {
+                /**
+                 * ParentData provided through the parentData node will override the data provided
+                 * through a modifier.
+                 */
+                measureScope.modifyParentData(next.parentData)
+            }
+        }
+
     final override val parentLayoutCoordinates: LayoutCoordinates?
         get() {
             check(isAttached) { ExpectAttachedLayoutCoordinates }
diff --git a/compose/ui/ui/src/commonMain/kotlin/androidx/compose/ui/node/ModifiedParentDataNode.kt b/compose/ui/ui/src/commonMain/kotlin/androidx/compose/ui/node/ModifiedParentDataNode.kt
deleted file mode 100644
index 521c2c0..0000000
--- a/compose/ui/ui/src/commonMain/kotlin/androidx/compose/ui/node/ModifiedParentDataNode.kt
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * Copyright 2020 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package androidx.compose.ui.node
-
-import androidx.compose.ui.layout.ParentDataModifier
-
-internal class ModifiedParentDataNode(
-    wrapped: LayoutNodeWrapper,
-    parentDataModifier: ParentDataModifier
-) : DelegatingLayoutNodeWrapper<ParentDataModifier>(wrapped, parentDataModifier) {
-    override val parentData: Any?
-        get() = with(modifier) {
-            /**
-             * ParentData provided through the parentData node will override the data provided
-             * through a modifier
-             */
-            layoutNode.measureScope.modifyParentData(wrapped.parentData)
-        }
-}
\ No newline at end of file
diff --git a/compose/ui/ui/src/commonMain/kotlin/androidx/compose/ui/node/SimpleEntity.kt b/compose/ui/ui/src/commonMain/kotlin/androidx/compose/ui/node/SimpleEntity.kt
new file mode 100644
index 0000000..4c471ff
--- /dev/null
+++ b/compose/ui/ui/src/commonMain/kotlin/androidx/compose/ui/node/SimpleEntity.kt
@@ -0,0 +1,27 @@
+/*
+ * Copyright 2022 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package androidx.compose.ui.node
+
+import androidx.compose.ui.Modifier
+
+/**
+ * A [LayoutNodeEntity] that only contains a [Modifier] and no logic
+ */
+internal class SimpleEntity<M : Modifier>(
+    layoutNodeWrapper: LayoutNodeWrapper,
+    modifier: M
+) : LayoutNodeEntity<SimpleEntity<M>, M>(layoutNodeWrapper, modifier)
\ No newline at end of file