Skip to content

Commit

Permalink
Merge pull request #10 from cheonjaewoong/optimizing
Browse files Browse the repository at this point in the history
Optimize internal loops using fastForEach of compose ui utils
  • Loading branch information
cheonjaeung authored Dec 23, 2023
2 parents 9e339e5 + 03efe1a commit b5ae7de
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
2 changes: 2 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ maven-publish = { id = "com.vanniktech.maven.publish", version = "0.25.3" }
androidx-core = { module = "androidx.core:core", version = "1.10.1" }
compose-multiplatform-runtime = { module = "org.jetbrains.compose.runtime:runtime", version.ref = "compose-multiplatform" }
compose-multiplatform-foundation = { module = "org.jetbrains.compose.foundation:foundation", version.ref = "compose-multiplatform" }
compose-multiplatform-ui-util = { module = "org.jetbrains.compose.ui:ui-util", version.ref = "compose-multiplatform" }
compose-android-runtime = { module = "androidx.compose.runtime:runtime", version.ref = "compose-android" }
compose-android-foundation = { module = "androidx.compose.foundation:foundation", version.ref = "compose-android" }
compose-android-ui-util = { module = "androidx.compose.ui:ui-util", version.ref = "compose-android" }

# Test dependencies
junit4 = { module = "junit:junit", version = "4.13.2" }
Expand Down
2 changes: 2 additions & 0 deletions grid/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ kotlin {
dependencies {
implementation(libs.compose.multiplatform.runtime)
implementation(libs.compose.multiplatform.foundation)
implementation(libs.compose.multiplatform.ui.util)
}
}
val commonTest by getting
Expand All @@ -25,6 +26,7 @@ kotlin {
implementation(libs.androidx.core)
implementation(libs.compose.android.runtime)
implementation(libs.compose.android.foundation)
implementation(libs.compose.android.ui.util)
}
}
val androidInstrumentedTest by getting {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import androidx.compose.ui.unit.Constraints
import androidx.compose.ui.unit.Density
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.LayoutDirection
import androidx.compose.ui.util.fastForEach
import kotlin.math.max
import kotlin.math.min

Expand Down Expand Up @@ -265,10 +266,10 @@ internal class GridMeasureHelper(

val placeableInfoTable = mutableListOf<List<PlaceablePositionInfo>>()
var mainAxisIndex = 0
placeableSpanInfoTable.forEach { placeableLine ->
placeableSpanInfoTable.fastForEach { placeableLine ->
val placeableInfoLine = mutableListOf<PlaceablePositionInfo>()
var crossAxisIndex = 0
placeableLine.forEach { placeableSpanInfo ->
placeableLine.fastForEach { placeableSpanInfo ->
placeableInfoLine.add(
PlaceablePositionInfo(
placeable = placeableSpanInfo.placeable,
Expand Down Expand Up @@ -297,8 +298,8 @@ internal class GridMeasureHelper(
arrangeResult: GridArrangeResult,
) = with(placeableScope) {
val placeableInfoTable = arrangeResult.placeablePositionInfoTable
placeableInfoTable.forEach { placeableInfoLine ->
placeableInfoLine.forEach { placeableInfo ->
placeableInfoTable.fastForEach { placeableInfoLine ->
placeableInfoLine.fastForEach { placeableInfo ->
val placeable = placeableInfo.placeable
if (orientation == LayoutOrientation.Horizontal) {
placeable.place(
Expand Down

0 comments on commit b5ae7de

Please sign in to comment.