-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Import Data and DataProtocol from the overlay (and correct some incorrect CFData and NSData usages) #1834
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
Conversation
…rect CFData and NSData usages)
@swift-ci please test |
@@ -130,15 +130,19 @@ add_swift_library(Foundation | |||
Foundation/CGFloat.swift | |||
Foundation/CharacterSet.swift | |||
Foundation/Codable.swift | |||
Foundation/Collections+DataProtocol.swift |
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.
I sorted this section: hopefully that does not pose any issue.
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.
If it does, it will be immediately apparent. The places where things were out of order were due to the compiler requiring the interfaces to be processed earlier.
@@ -377,7 +374,6 @@ static Boolean __CFDataShouldUseAllocator(CFAllocatorRef allocator) { | |||
// that there should be no deallocator, and the bytes should be copied. | |||
static CFMutableDataRef __CFDataInit(CFAllocatorRef allocator, _CFDataMutableVariety variety, CFIndex capacity, const uint8_t *bytes, CFIndex length, CFAllocatorRef bytesDeallocator) CF_RETURNS_RETAINED { | |||
CFMutableDataRef memory; | |||
__CFGenericValidateMutability(variety); |
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 inappropriate and does not match the Darwin behavior.
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.
It must've been a merge artifact.
@@ -31,7 +31,11 @@ let kNullString = "<null>" | |||
private func getTestData() -> [Any]? { | |||
let testFilePath = testBundle().url(forResource: "NSURLTestData", withExtension: "plist") | |||
let data = try! Data(contentsOf: testFilePath!) | |||
guard let testRoot = try? PropertyListSerialization.propertyList(from: data, options: [], format: nil) as? [String : Any] else { | |||
guard let plist = try? PropertyListSerialization.propertyList(from: data, options: [], format: nil) else { |
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 an error in the latest toolchain
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.
Oh I'm sorry that #1829 conflicts with this 😓
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.
Eh no worries: I was just trying to ensure a good state by testing on macOS. As long as the test is validly fixed it does not matter if it is from your commit or mine imo
@@ -1421,10 +1421,6 @@ extension TestNSData { | |||
} | |||
|
|||
func test_dataHash() { | |||
let dataStruct = "Hello World".data(using: .utf8)! |
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 test is no longer valid
@@ -23,9 +23,7 @@ import Dispatch | |||
/// Turn `Data` into `DispatchData` | |||
internal func createDispatchData(_ data: Data) -> DispatchData { | |||
//TODO: Avoid copying data | |||
let buffer = UnsafeRawBufferPointer(start: data._backing.bytes, |
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 was super-unsafe!
@@ -179,7 +179,9 @@ open class NSData : NSObject, NSCopying, NSMutableCopying, NSSecureCoding { | |||
/// Initializes a data object with the contents of another data object. | |||
public init(data: Data) { | |||
super.init() | |||
_init(bytes: UnsafeMutableRawPointer(mutating: data._nsObject.bytes), length: data.count, copy: true) |
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.
I am not quite sure how this didnt crash before. The new version is considerably safer
@swift-ci please test |
1 similar comment
@swift-ci please test |
…d inline/objc decorators
0ab7132
to
82f3236
Compare
@swift-ci please test |
1 similar comment
@swift-ci please test |
@phausler will this also go to |
@weissi Yes. I'm working on the cherry-pick. |
Thanks very much @millenomi |
This brings in the new 2-word implementation of Data which adds numerous performance improvements that reduce the overhead of using Data. Particularly certain optimized scenarios will instead of using heap allocations for Data it now uses a stack switching implementation (similar to the smol String implementation). Additionally this brings in a new protocol called DataProtocol which unifies Data like types to be usable in a generic fashion. This codifies a concept of contiguous byte storage so that types such as DispatchData which represent a collection of contiguous regions can share a similar interface to those with full contiguous storage like Data or Array etc.