You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Added @inlinable to most functions (and computed properties).
Also added @inline(__always) to some, where they're particularly trivial (e.g. just aliases, in essence, for another function).
Most of these functions probably aren't performance sensitive - though some are, so the benefit for them is most obvious - but even for those that aren't, being inlinable apparently allows the optimiser to make better decisions (like omitting redundant calls entirely) which could be an aid to reducing malloc activity.
Copy file name to clipboardExpand all lines: Sources/FoundationExtensions/BidirectionalCollection.swift
+1Lines changed: 1 addition & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -9,6 +9,7 @@ public extension BidirectionalCollection {
9
9
///
10
10
/// - Parameter transform: The transform to apply, returning a value if successful or nil otherwise. This _must_ have a single transition point (where it goes from returning values to returning nil, for increasingly long prefixes), else the result is undefined.
11
11
/// - Returns: The result of a transformation closure on the longest prefix for which the transform succeeds, or nil if there is no [non-empty] prefix for which this is the case.
Copy file name to clipboardExpand all lines: Sources/FoundationExtensions/BinaryInteger.swift
+2Lines changed: 2 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -6,6 +6,7 @@ public extension BinaryInteger {
6
6
/// Returns the individual bits of the integer, split out into an array.
7
7
///
8
8
/// Not to be confused with ``bitIndices``, which is similar but the resulting array has the index of each bit that is set in the integer (`self`), not the value of that bit.
9
+
@inlinable
9
10
varbits:[Self]{
10
11
varremainder=self
11
12
varresult=[Self]()
@@ -24,6 +25,7 @@ public extension BinaryInteger {
24
25
/// Returns the indices of each `1` bit of the integer.
25
26
///
26
27
/// Not to be confused with ``bits``, which is similar but the resulting array contains the component numbers themselves.
Copy file name to clipboardExpand all lines: Sources/FoundationExtensions/CollectionOfUInt8.swift
+2Lines changed: 2 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -58,6 +58,8 @@ public extension Collection where Element == UInt8 {
58
58
/// An ASCII representation of the given collection's ``UInt8`` contents, in uppercase and without any spaces.
59
59
///
60
60
/// This is equivalent to calling ``asHexString(uppercase:delimiterEvery:delimiter:)`` with default arguments. It is provided as a convenience so that the parentheses may be omitted.
Copy file name to clipboardExpand all lines: Sources/FoundationExtensions/Date.swift
+3-1Lines changed: 3 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -4,7 +4,8 @@
4
4
import Foundation
5
5
6
6
publicextensionDate{
7
-
privatestaticletrelativeDateTimeFormatter={
7
+
@usableFromInline
8
+
internalstaticletrelativeDateTimeFormatter={
8
9
varformatter=RelativeDateTimeFormatter()
9
10
formatter.dateTimeStyle =.named
10
11
formatter.unitsStyle =.full
@@ -15,6 +16,7 @@ public extension Date {
15
16
/// Returns a human-readable, localised description of how long ago the date was, e.g. "2 hours ago".
16
17
///
17
18
/// The description may be approximate, typically limited to only the first significant date & time component (e.g. just "2 hours ago" for deltas ranging from 1.5 to 2.5 hours ago).
Copy file name to clipboardExpand all lines: Sources/FoundationExtensions/IteratorProtocol.swift
+10-1Lines changed: 10 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -4,13 +4,17 @@ public extension IteratorProtocol {
4
4
/// Returns a type-erased version of the iterator (an `AnyIterator`).
5
5
///
6
6
/// This is a 'convenience' property to make `AnyIterator` more accessible, such as when using optional chaining.
7
+
@inlinable
8
+
@inline(__always)
7
9
vartypeErased:AnyIterator<Element>{
8
10
AnyIterator(self)
9
11
}
10
12
11
13
/// Returns an async iterator wrapper over the iterator.
12
14
///
13
15
/// Be careful in how you use this - Swift Concurrency contexts (async functions, inside Tasks, etc) basically do not support blocking code (their performance suffers, and it can lead to deadlock). You should only use this for iterators that do not block (i.e. do not do any I/O, do not take any locks, etc), such as simple enumeration of `Array`s and the like.
16
+
@inlinable
17
+
@inline(__always)
14
18
varasync:AsyncIteratorOverSyncIterator<Self>{
15
19
AsyncIteratorOverSyncIterator(self)
16
20
}
@@ -22,12 +26,17 @@ public extension IteratorProtocol {
0 commit comments