[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

@@ -112,7 +112,7 @@ extension NullEncodable: Codable where Wrapped: Codable {
}
{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} final class RequestTask{{#useAsyncAwait}}: @unchecked Sendable{{/useAsyncAwait}} {
private var lock = NSRecursiveLock()
private let lock = NSRecursiveLock()
{{#useAlamofire}}
private var request: Request?

View File

@@ -9,28 +9,18 @@ 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]
}
return value
lock.lock()
defer { lock.unlock() }
return self.dictionary[key]
}
set {
queue.sync(flags: DispatchWorkItemFlags.barrier) {
self.dictionary[key] = newValue
}
lock.lock()
defer { lock.unlock() }
self.dictionary[key] = newValue
}
}
}

View File

@@ -585,7 +585,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"

View File

@@ -128,7 +128,7 @@ extension NullEncodable: Codable where Wrapped: Codable {
}{{/useAlamofire}}
{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} final class RequestTask{{#useAsyncAwait}}: @unchecked Sendable{{/useAsyncAwait}} {
private var lock = NSRecursiveLock()
private let lock = NSRecursiveLock()
{{#useAlamofire}}
private var request: Request?

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"