Skip to content

Commit

Permalink
Improve inlining (#30)
Browse files Browse the repository at this point in the history
  • Loading branch information
czechboy0 authored Nov 24, 2023
1 parent 9229842 commit 7d33846
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 23 deletions.
40 changes: 20 additions & 20 deletions Sources/OpenAPIURLSession/BufferedStream/BufferedStream.swift
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ internal struct BufferedStream<Element> {
@usableFromInline
let storage: _BackPressuredStorage

@inlinable
@usableFromInline
init(storage: _BackPressuredStorage) {
self.storage = storage
}
Expand Down Expand Up @@ -171,7 +171,7 @@ extension BufferedStream: AsyncSequence {
@usableFromInline
let storage: _BackPressuredStorage

@inlinable
@usableFromInline
init(storage: _BackPressuredStorage) {
self.storage = storage
self.storage.iteratorInitialized()
Expand All @@ -191,7 +191,7 @@ extension BufferedStream: AsyncSequence {
@usableFromInline
var implementation: _Implementation

@inlinable
@usableFromInline
init(implementation: _Implementation) {
self.implementation = implementation
}
Expand Down Expand Up @@ -237,7 +237,7 @@ internal struct _ManagedCriticalState<State>: @unchecked Sendable {
@usableFromInline
let lock: LockedValueBox<State>

@inlinable
@usableFromInline
internal init(_ initial: State) {
self.lock = .init(initial)
}
Expand All @@ -252,7 +252,7 @@ internal struct _ManagedCriticalState<State>: @unchecked Sendable {

@usableFromInline
internal struct AlreadyFinishedError: Error {
@inlinable
@usableFromInline
init() {}
}

Expand Down Expand Up @@ -289,7 +289,7 @@ extension BufferedStream {
)
}

@inlinable
@usableFromInline
init(internalBackPressureStrategy: _InternalBackPressureStrategy) {
self._internalBackPressureStrategy = internalBackPressureStrategy
}
Expand Down Expand Up @@ -329,7 +329,7 @@ extension BufferedStream {
@usableFromInline
let storage: _BackPressuredStorage

@inlinable
@usableFromInline
init(storage: _BackPressuredStorage) {
self.storage = storage
}
Expand Down Expand Up @@ -359,7 +359,7 @@ extension BufferedStream {
@usableFromInline
var _backing: _Backing

@inlinable
@usableFromInline
internal init(storage: _BackPressuredStorage) {
self._backing = .init(storage: storage)
}
Expand Down Expand Up @@ -580,7 +580,7 @@ extension BufferedStream {
return (.init(storage: storage), source)
}

@inlinable
@usableFromInline
init(storage: _BackPressuredStorage) {
self.implementation = .backpressured(.init(storage: storage))
}
Expand Down Expand Up @@ -609,7 +609,7 @@ extension BufferedStream {
/// - low: The low watermark where demand should start.
/// - high: The high watermark where demand should be stopped.
/// - waterLevelForElement: Function to compute the contribution to the water level for a given element.
@inlinable
@usableFromInline
init(low: Int, high: Int, waterLevelForElement: (@Sendable (Element) -> Int)? = nil) {
precondition(low <= high)
self._low = low
Expand All @@ -618,7 +618,7 @@ extension BufferedStream {
self._waterLevelForElement = waterLevelForElement
}

@inlinable
@usableFromInline
mutating func didYield(elements: Deque<Element>.SubSequence) -> Bool {
if let waterLevelForElement = self._waterLevelForElement {
self._current += elements.reduce(0) { $0 + waterLevelForElement($1) }
Expand All @@ -630,7 +630,7 @@ extension BufferedStream {
return self._current < self._high
}

@inlinable
@usableFromInline
mutating func didConsume(elements: Deque<Element>.SubSequence) -> Bool {
if let waterLevelForElement = self._waterLevelForElement {
self._current -= elements.reduce(0) { $0 + waterLevelForElement($1) }
Expand All @@ -642,7 +642,7 @@ extension BufferedStream {
return self._current < self._low
}

@inlinable
@usableFromInline
mutating func didConsume(element: Element) -> Bool {
if let waterLevelForElement = self._waterLevelForElement {
self._current -= waterLevelForElement(element)
Expand All @@ -669,7 +669,7 @@ extension BufferedStream {
}
}

@inlinable
@usableFromInline
mutating func didConsume(elements: Deque<Element>.SubSequence) -> Bool {
switch self {
case .watermark(var strategy):
Expand All @@ -679,7 +679,7 @@ extension BufferedStream {
}
}

@inlinable
@usableFromInline
mutating func didConsume(element: Element) -> Bool {
switch self {
case .watermark(var strategy):
Expand Down Expand Up @@ -714,7 +714,7 @@ extension BufferedStream {
}
}

@inlinable
@usableFromInline
init(
backPressureStrategy: _InternalBackPressureStrategy
) {
Expand Down Expand Up @@ -1026,7 +1026,7 @@ extension BufferedStream {
@usableFromInline
var onTermination: (@Sendable () -> Void)?

@inlinable
@usableFromInline
init(
backPressureStrategy: _InternalBackPressureStrategy,
iteratorInitialized: Bool,
Expand Down Expand Up @@ -1065,7 +1065,7 @@ extension BufferedStream {
@usableFromInline
var hasOutstandingDemand: Bool

@inlinable
@usableFromInline
init(
backPressureStrategy: _InternalBackPressureStrategy,
iteratorInitialized: Bool,
Expand Down Expand Up @@ -1102,7 +1102,7 @@ extension BufferedStream {
@usableFromInline
var onTermination: (@Sendable () -> Void)?

@inlinable
@usableFromInline
init(
iteratorInitialized: Bool,
buffer: Deque<Element>,
Expand Down Expand Up @@ -1188,7 +1188,7 @@ extension BufferedStream {
/// it is a customizable extension of the state machine.
///
/// - Parameter backPressureStrategy: The back-pressure strategy.
@inlinable
@usableFromInline
init(
backPressureStrategy: _InternalBackPressureStrategy
) {
Expand Down
6 changes: 3 additions & 3 deletions Sources/OpenAPIURLSession/BufferedStream/Lock.swift
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ final class LockStorage<Value>: ManagedBuffer<Value, LockPrimitive> {
}
}

@inlinable
@usableFromInline
deinit {
self.withUnsafeMutablePointerToElements { lockPtr in
LockOperations.destroy(lockPtr)
Expand Down Expand Up @@ -176,7 +176,7 @@ struct Lock {
internal let _storage: LockStorage<Void>

/// Create a new lock.
@inlinable
@usableFromInline
init() {
self._storage = .create(value: ())
}
Expand Down Expand Up @@ -240,7 +240,7 @@ struct LockedValueBox<Value> {
@usableFromInline
let storage: LockStorage<Value>

@inlinable
@usableFromInline
init(_ value: Value) {
self.storage = .create(value: value)
}
Expand Down

0 comments on commit 7d33846

Please sign in to comment.