Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -157,17 +157,17 @@ internal class ComposeUiClusterRenderer<T : ClusterItem>(
.flatMap { it.items }
.toSet()

val keys = clusters.flatMap { it.computeViewKeys() }
val keys = clusters.flatMapTo(mutableSetOf()) { it.computeViewKeys() }

with(keysToViews.iterator()) {
forEach { (key, viewInfo) ->
if (key !in keys) {
remove()
viewInfo.onRemove()
}
val iterator = keysToViews.iterator()

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This hunk is a genuine improvement. The old with(keysToViews.iterator()) { forEach { ... remove() } } was fragile, relying on the interplay between Iterator.forEach and MutableIterator.remove. The explicit while (hasNext()) is clearer and obviously correct. 👍

I'd just reframe it in the PR description though: the forEach to for swaps elsewhere (lines 127 and 169) are readability only. Iterable.forEach and Map.forEach are inline, so the bytecode is effectively identical and there's no perf win to claim there.

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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ public inline fun rememberCameraPositionState(
"com.google.maps.android.compose.rememberCameraPositionState",
),
)
@Suppress("DEPRECATION")
@Composable
public inline fun rememberCameraPositionState(
key: String? = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,14 +193,9 @@ public class MarkerState private constructor(position: LatLng) {
message = "Use 'rememberUpdatedMarkerState' instead - It may be confusing to think " +
"that the state is automatically updated as the position changes, " +
"so it will be changed or removed.",
replaceWith = ReplaceWith(
expression = """
val markerState = rememberSaveable(key = key, saver = MarkerState.Saver) {
MarkerState(position)
}
""",
),
replaceWith = ReplaceWith("rememberUpdatedMarkerState(position)"),
)
@Suppress("DEPRECATION")
public fun rememberMarkerState(key: String? = null, position: LatLng = LatLng(0.0, 0.0)): MarkerState =
rememberSaveable(key = key, saver = MarkerState.Saver) {
MarkerState(position)
Expand Down
Loading