swiftlang / swift-corelibs-foundation

The Foundation Project, providing core utilities, internationalization, and OS independence
swift.org
Apache License 2.0
5.29k stars 1.13k forks source link

Fix a leak when mutating CharacterSet by moving away from _SwiftNSCharacterSet wrapper #5107

Closed parkera closed 1 month ago

parkera commented 1 month ago

CharacterSet was the one remaining type in swift-corelibs-foundation using a wrapper type to handle moving between immutable/mutable and handling uniqueness checks. By removing the wrapper and simplifying the usage, we can also remove the leak from mismanaging an "Unmanaged" CF type reference.

rdar://137806932

parkera commented 1 month ago

@swift-ci test

itingliu commented 1 month ago

Also we probably want this for 6.0.2 as well

parkera commented 1 month ago

Did you know if the boxing was introduced to address some issues, or was that preventive?

It was an abstraction for the several types that used this pattern. But this is the only one left, so it has outlived its usefulness. The Unmanaged part of it was an attempt to avoid accidentally increasing the retain count so copy-on-write worked correctly.