Skip to content

Commit 5cde0b1

Browse files
authored
Inline all the reductions things! (#114)
1 parent 220649e commit 5cde0b1

File tree

1 file changed

+26
-34
lines changed

1 file changed

+26
-34
lines changed

Sources/Algorithms/Reductions.swift

Lines changed: 26 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ public struct ExclusiveReductions<Result, Base: Sequence> {
189189
@usableFromInline
190190
internal let transform: (inout Result, Base.Element) -> Void
191191

192-
@usableFromInline
192+
@inlinable
193193
internal init(
194194
base: Base,
195195
initial: Result,
@@ -212,7 +212,7 @@ extension ExclusiveReductions: Sequence {
212212
@usableFromInline
213213
internal let transform: (inout Result, Base.Element) -> Void
214214

215-
@usableFromInline
215+
@inlinable
216216
internal init(
217217
iterator: Base.Iterator,
218218
current: Result? = nil,
@@ -249,27 +249,23 @@ extension ExclusiveReductions: Collection where Base: Collection {
249249
internal let representation: ReductionsIndexRepresentation<Base.Index, Result>
250250

251251
@inlinable
252-
public static func < (lhs: Self, rhs: Self) -> Bool {
253-
lhs.representation < rhs.representation
252+
internal init(
253+
_ representation: ReductionsIndexRepresentation<Base.Index, Result>
254+
) {
255+
self.representation = representation
254256
}
255257

256-
@usableFromInline
257-
internal static func base(index: Base.Index, result: Result) -> Self {
258-
Self(representation: .base(index: index, result: result))
258+
@inlinable
259+
public static func < (lhs: Self, rhs: Self) -> Bool {
260+
lhs.representation < rhs.representation
259261
}
260-
261-
@usableFromInline
262-
internal static var start: Self { Self(representation: .start) }
263-
264-
@usableFromInline
265-
internal static var end: Self { Self(representation: .end) }
266262
}
267263

268264
@inlinable
269-
public var startIndex: Index { .start }
265+
public var startIndex: Index { Index(.start) }
270266

271267
@inlinable
272-
public var endIndex: Index { .end }
268+
public var endIndex: Index { Index(.end) }
273269

274270
@inlinable
275271
public subscript(position: Index) -> Result {
@@ -286,7 +282,7 @@ extension ExclusiveReductions: Collection where Base: Collection {
286282
guard index != base.endIndex else { return endIndex }
287283
var previous = previous
288284
transform(&previous, base[index])
289-
return .base(index: index, result: previous)
285+
return Index(.base(index: index, result: previous))
290286
}
291287
switch i.representation {
292288
case .start:
@@ -414,7 +410,7 @@ public struct InclusiveReductions<Base: Sequence> {
414410
@usableFromInline
415411
internal let transform: (Base.Element, Base.Element) -> Base.Element
416412

417-
@usableFromInline
413+
@inlinable
418414
internal init(
419415
base: Base,
420416
transform: @escaping (Base.Element, Base.Element) -> Base.Element
@@ -435,7 +431,7 @@ extension InclusiveReductions: Sequence {
435431
@usableFromInline
436432
internal let transform: (Base.Element, Base.Element) -> Base.Element
437433

438-
@usableFromInline
434+
@inlinable
439435
internal init(
440436
iterator: Base.Iterator,
441437
element: Base.Element? = nil,
@@ -471,30 +467,26 @@ extension InclusiveReductions: Collection where Base: Collection {
471467
internal let representation: ReductionsIndexRepresentation<Base.Index, Base.Element>
472468

473469
@inlinable
474-
public static func < (lhs: Self, rhs: Self) -> Bool {
475-
lhs.representation < rhs.representation
470+
internal init(
471+
_ representation: ReductionsIndexRepresentation<Base.Index, Base.Element>
472+
) {
473+
self.representation = representation
476474
}
477475

478-
@usableFromInline
479-
internal static func base(index: Base.Index, result: Base.Element) -> Self {
480-
Self(representation: .base(index: index, result: result))
476+
@inlinable
477+
public static func < (lhs: Self, rhs: Self) -> Bool {
478+
lhs.representation < rhs.representation
481479
}
482-
483-
@usableFromInline
484-
internal static var start: Self { Self(representation: .start) }
485-
486-
@usableFromInline
487-
internal static var end: Self { Self(representation: .end) }
488480
}
489481

490482
@inlinable
491483
public var startIndex: Index {
492484
guard base.startIndex != base.endIndex else { return endIndex }
493-
return .start
485+
return Index(.start)
494486
}
495487

496488
@inlinable
497-
public var endIndex: Index { .end }
489+
public var endIndex: Index { Index(.end) }
498490

499491
@inlinable
500492
public subscript(position: Index) -> Base.Element {
@@ -510,7 +502,7 @@ extension InclusiveReductions: Collection where Base: Collection {
510502
func index(after i: Base.Index, previous: Base.Element) -> Index {
511503
let index = base.index(after: i)
512504
guard index != base.endIndex else { return endIndex }
513-
return .base(index: index, result: transform(previous, base[index]))
505+
return Index(.base(index: index, result: transform(previous, base[index])))
514506
}
515507
switch i.representation {
516508
case .start:
@@ -563,7 +555,7 @@ enum ReductionsIndexRepresentation<BaseIndex: Comparable, Result> {
563555
}
564556

565557
extension ReductionsIndexRepresentation: Equatable {
566-
@usableFromInline
558+
@inlinable
567559
static func == (lhs: Self, rhs: Self) -> Bool {
568560
switch (lhs, rhs) {
569561
case (.start, .start): return true
@@ -575,7 +567,7 @@ extension ReductionsIndexRepresentation: Equatable {
575567
}
576568

577569
extension ReductionsIndexRepresentation: Comparable {
578-
@usableFromInline
570+
@inlinable
579571
static func < (lhs: Self, rhs: Self) -> Bool {
580572
switch (lhs, rhs) {
581573
case (_, .start): return false

0 commit comments

Comments
 (0)