-
Notifications
You must be signed in to change notification settings - Fork 181
feat(clustering,maps-compose): remove deprecated rememberSaveable key and optimize loops #983
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -124,7 +124,7 @@ internal class ComposeUiClusterRenderer<T : ClusterItem>( | |
| clusterItemContentZIndexState.value, | ||
| ) | ||
| }.collect { | ||
| keysToViews.forEach { (key, viewInfo) -> | ||
| for ((key, viewInfo) in keysToViews) { | ||
| when (key) { | ||
| is ViewKey.Cluster -> { | ||
| getMarker(key.cluster)?.apply { | ||
|
|
@@ -158,15 +158,15 @@ internal class ComposeUiClusterRenderer<T : ClusterItem>( | |
|
|
||
| val keys = clusters.flatMap { it.computeViewKeys() } | ||
|
|
||
| with(keysToViews.iterator()) { | ||
| forEach { (key, viewInfo) -> | ||
| if (key !in keys) { | ||
| remove() | ||
| viewInfo.onRemove() | ||
| } | ||
| val iterator = keysToViews.iterator() | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This hunk is a genuine improvement. The old I'd just reframe it in the PR description though: the |
||
| while (iterator.hasNext()) { | ||
| val (key, viewInfo) = iterator.next() | ||
| if (key !in keys) { | ||
| iterator.remove() | ||
| viewInfo.onRemove() | ||
| } | ||
| } | ||
| keys.forEach { key -> | ||
| for (key in keys) { | ||
| if (key !in keysToViews.keys) { | ||
| createAndAddView(key) | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,8 +14,6 @@ | |
| package com.google.maps.android.compose | ||
|
|
||
| import androidx.compose.runtime.Immutable | ||
| import com.google.maps.android.compose.CameraMoveStartedReason.Companion.fromInt | ||
| import com.google.maps.android.compose.CameraMoveStartedReason.NO_MOVEMENT_YET | ||
| import com.google.maps.android.compose.CameraMoveStartedReason.UNKNOWN | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Anchoring here since the two removed lines only exist on the left side of the diff. The removed It's also inconsistent: this |
||
|
|
||
| /** | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -72,7 +72,7 @@ public inline fun rememberCameraPositionState( | |
| public inline fun rememberCameraPositionState( | ||
| key: String? = null, | ||
| crossinline init: CameraPositionState.() -> Unit = {} | ||
| ): CameraPositionState = rememberSaveable(key = key, saver = CameraPositionState.Saver) { | ||
| ): CameraPositionState = rememberSaveable(saver = CameraPositionState.Saver) { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is inside the
I grepped every Suggestion: leave the body as it was and silence the warning instead, then delete the overload wholesale at the next major, where removing @Suppress("DEPRECATION")
@Composable
public inline fun rememberCameraPositionState(
key: String? = null,
crossinline init: CameraPositionState.() -> Unit = {}
): CameraPositionState = rememberSaveable(key = key, saver = CameraPositionState.Saver) {If you'd rather keep it as written, that's defensible given the function is already deprecated, but it needs a release-note line pointing loop and pager users at |
||
| CameraPositionState().apply(init) | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -195,7 +195,7 @@ public class MarkerState private constructor(position: LatLng) { | |
| "so it will be changed or removed.", | ||
| replaceWith = ReplaceWith( | ||
| expression = """ | ||
| val markerState = rememberSaveable(key = key, saver = MarkerState.Saver) { | ||
| val markerState = rememberSaveable(saver = MarkerState.Saver) { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Non-blocking, but while we're in here: this Either |
||
| MarkerState(position) | ||
| } | ||
| """ | ||
|
|
@@ -204,7 +204,7 @@ public class MarkerState private constructor(position: LatLng) { | |
| public fun rememberMarkerState( | ||
| key: String? = null, | ||
| position: LatLng = LatLng(0.0, 0.0) | ||
| ): MarkerState = rememberSaveable(key = key, saver = MarkerState.Saver) { | ||
| ): MarkerState = rememberSaveable(saver = MarkerState.Saver) { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as One extra wrinkle here. The deprecation message on line 193 only talks about |
||
| MarkerState(position) | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is where the "optimize loops" in the title could actually land.
keysis aList, sokey !in keyson line 164 is a linear scan run once per entry inkeysToViews, makingonClustersChangedO(n*m) on every cluster change.computeViewKeys()already returns aSet, so:That makes both membership checks O(1) and dedupes safely (the
for (key in keys)loop below adds into a map, so duplicates were never wanted). With a few hundred markers this is the difference that's actually measurable, unlike theforEachtoforswaps.