Skip to content

Commit fef7e1a

Browse files
committed
add is identical methods updates
1 parent 7490512 commit fef7e1a

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

proposals/0494-add-is-identical-methods.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,8 @@ struct FavoriteContactList: View {
171171
}
172172
```
173173

174+
We can assume there is another view component in our application that could be editing these `Contact` values. It's not very important for us right now to show *how* these `Contact` values could change — let's just assume that our `FavoriteContactList` component might need to recompute its `body` over time with new `Contact` values.
175+
174176
When we compute our `body` property we also compute our `favorites` property. The implication is that *every* time our `body` property is computed we perform *another* `O(n)` algorithm across our `contacts`. Because our `FavoriteContactList` supports selection, every time our user selects a `Contact` value we update our `State`. Updating our `State` computes our `body` which computes our `favorites` property. So even though our `contacts` values *have not changed*, we *still* pay the performance penalty of *another* `O(n)` operation just to support cell selection.
175177

176178
This might look like a good opportunity for another attempt at memoization. Here is an approach using a dynamic property wrapper:
@@ -715,6 +717,8 @@ Thanks to [David Nadoba](https://forums.swift.org/t/-/80496/61/) for proposing t
715717

716718
Thanks to [Xiaodi Wu](https://forums.swift.org/t/-/80496/67) for proposing that our equivalence relation semantics would carve-out for “exceptional” values like `Float.nan`.
717719

720+
Thanks to [QuinceyMorris](https://forums.swift.org/t/-/82296/72) for proposing the name `isTriviallyIdentical(to:)`.
721+
718722
[^1]: https://github.com/swiftlang/swift/blob/swift-6.1.2-RELEASE/stdlib/public/core/String.swift#L397-L415
719723
[^2]: https://github.com/apple/swift-collections/blob/1.2.0/Sources/DequeModule/Deque._Storage.swift#L223-L225
720724
[^3]: https://github.com/apple/swift-collections/blob/1.2.0/Sources/HashTreeCollections/HashNode/_HashNode.swift#L78-L80

0 commit comments

Comments
 (0)