[swift] small improvements (#19675)

* [swift] small improments

* [swift] small improments

* [swift] small improments

* [swift] make CI pass

* [swift] make CI pass

* [swift] make CI pass

* [swift] make CI pass

* [swift] make CI pass

* [swift] make CI pass

* [swift] make CI pass
This commit is contained in:
Bruno Coelho
2024-09-27 06:11:08 +01:00
committed by GitHub
parent 76aca6618f
commit 911455d206
1321 changed files with 1282 additions and 81137 deletions

View File

@@ -111,7 +111,7 @@ open class Response<T> {
}
public final class RequestTask: @unchecked Sendable {
private var lock = NSRecursiveLock()
private let lock = NSRecursiveLock()
private var task: URLSessionDataTaskProtocol?
internal func set(task: URLSessionDataTaskProtocol) {

View File

@@ -9,26 +9,16 @@ import Foundation
internal struct SynchronizedDictionary<K: Hashable, V> {
private var dictionary = [K: V]()
private let queue = DispatchQueue(
label: "SynchronizedDictionary",
qos: DispatchQoS.userInitiated,
attributes: [DispatchQueue.Attributes.concurrent],
autoreleaseFrequency: DispatchQueue.AutoreleaseFrequency.inherit,
target: nil
)
private let lock = NSRecursiveLock()
internal subscript(key: K) -> V? {
get {
var value: V?
queue.sync {
value = self.dictionary[key]
lock.withLock {
self.dictionary[key]
}
return value
}
set {
queue.sync(flags: DispatchWorkItemFlags.barrier) {
lock.withLock {
self.dictionary[key] = newValue
}
}

View File

@@ -591,7 +591,7 @@ private class FormDataEncoding: ParameterEncoding {
func mimeType(for url: URL) -> String {
let pathExtension = url.pathExtension
if #available(iOS 15, macOS 11, *) {
if #available(macOS 11.0, iOS 14.0, tvOS 14.0, watchOS 7.0, *) {
#if canImport(UniformTypeIdentifiers)
if let utType = UTType(filenameExtension: pathExtension) {
return utType.preferredMIMEType ?? "application/octet-stream"