Hi Daniel, I will answer backwards, since it is easier for me this way.
> Am 14.07.2016 um 22:47 schrieb Daniel Resnick <[email protected]>: > > Furthermore, why should properties pointing to reference types always use > `===`? What if the reference type conforms to `Equatable`? I proposed to use `===`, since a value of a reference a value type is referencing is the reference itself. But point taken. So a solution could be to use `==` for reference types implementing `Equatable`. But wait for the punch-line below ;). > Forbidding custom `==` for value types would break equality for all Swift > collection types, since they use reference types behind the scenes for > storing memory and copy on write semantics. If the storage implements `Equatable`, this problem should be solved, right? Anyway (punch-line following), although I don’t know how exactly the low-level Value-Witness-Table works, but if it works as I would expect, then there should be only exactly one entry per „equal“ storage, and all collection types with the same data point to the same reference (which is very memory efficient and table lookup using hashing should be constant time). If this is correct, a check for `===` suffices. AFAIK, the low-level swift implementation already checks for `===` on value types that are stored on the heap (see [this blog post][0]) and don’t bother calling `==` if `===` holds. All the best Johannes [0]: https://www.raywenderlich.com/112029/reference-value-types-in-swift-part-2
signature.asc
Description: Message signed with OpenPGP using GPGMail
_______________________________________________ swift-evolution mailing list [email protected] https://lists.swift.org/mailman/listinfo/swift-evolution
