Skip to content

Commit

Permalink
Update PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
Kaspik committed Mar 26, 2019
1 parent 2803462 commit f00a2f6
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 58 deletions.
24 changes: 10 additions & 14 deletions Sources/Algorithm.swift
Original file line number Diff line number Diff line change
Expand Up @@ -326,15 +326,13 @@ public extension StagedChangeset where Collection: RangeReplaceableCollection, C
fourthStageElements.reserveCapacity(targetElements.count)

for targetElementIndex in targetElements.indices {
#if swift(>=5.0)
untrackedSourceIndex = untrackedSourceIndex.flatMap { index in
sourceElementTraces[sourceSectionIndex].suffix(from: index).firstIndex { !$0.isTracked }
#if swift(>=5.0)
return sourceElementTraces[sourceSectionIndex].suffix(from: index).firstIndex { !$0.isTracked }
#else
return sourceElementTraces[sourceSectionIndex].suffix(from: index).index { !$0.isTracked }
#endif
}
#else
untrackedSourceIndex = untrackedSourceIndex.flatMap { index in
sourceElementTraces[sourceSectionIndex].suffix(from: index).index { !$0.isTracked }
}
#endif

let targetElementPath = ElementPath(element: targetElementIndex, section: targetSectionIndex)
let targetElement = contiguousTargetSections[targetElementPath]
Expand Down Expand Up @@ -542,15 +540,13 @@ internal func differentiate<E: Differentiable, I>(

// Record the updates/moves/insertions.
for targetIndex in target.indices {
#if swift(>=5.0)
untrackedSourceIndex = untrackedSourceIndex.flatMap { index in
sourceTraces.suffix(from: index).firstIndex { !$0.isTracked }
}
#else
untrackedSourceIndex = untrackedSourceIndex.flatMap { index in
sourceTraces.suffix(from: index).index { !$0.isTracked }
#if swift(>=5.0)
return sourceTraces.suffix(from: index).firstIndex { !$0.isTracked }
#else
return sourceTraces.suffix(from: index).index { !$0.isTracked }
#endif
}
#endif

if let sourceIndex = targetReferences[targetIndex] {
sourceTraces[sourceIndex].isTracked = true
Expand Down
14 changes: 4 additions & 10 deletions Sources/Extensions/AppKitExtension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@ public extension NSTableView {
/// updates should be stopped and performed reloadData. Default is nil.
/// - setData: A closure that takes the collection as a parameter.
/// The collection should be set to data-source of NSTableView.
#if swift(>=5.0)

func reload<C>(
using stagedChangeset: StagedChangeset<C>,
with animation: @autoclosure () -> NSTableView.AnimationOptions,
interrupt: ((Changeset<C>) -> Bool)? = nil,
setData: (C) -> Void
) {
#if swift(>=5.0)
reload(
using: stagedChangeset,
deleteRowsAnimation: animation(),
Expand All @@ -30,14 +31,7 @@ public extension NSTableView {
interrupt: interrupt,
setData: setData
)
}
#else
func reload<C>(
using stagedChangeset: StagedChangeset<C>,
with animation: @autoclosure () -> NSTableView.AnimationOptions,
interrupt: ((Changeset<C>) -> Bool)? = nil,
setData: (C) -> Void
) {
#else
reload(
using: stagedChangeset,
deleteRowsAnimation: animation,
Expand All @@ -46,8 +40,8 @@ public extension NSTableView {
interrupt: interrupt,
setData: setData
)
#endif
}
#endif

/// Applies multiple animated updates in stages using `StagedChangeset`.
///
Expand Down
36 changes: 2 additions & 34 deletions Sources/StagedChangeset.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ public struct StagedChangeset<Collection: Swift.Collection> {
}
}

#if compiler(>=5.0)
/* Removes MutableCollection conformance as it is redundant. */
extension StagedChangeset: RandomAccessCollection, RangeReplaceableCollection {
@inlinable
public init() {
Expand Down Expand Up @@ -77,39 +75,9 @@ extension StagedChangeset: RandomAccessCollection, RangeReplaceableCollection {
changesets.replaceSubrange(subrange, with: newElements)
}
}
#else
extension StagedChangeset: RandomAccessCollection, RangeReplaceableCollection, MutableCollection {
@inlinable
public init() {
self.init([])
}

@inlinable
public var startIndex: Int {
return changesets.startIndex
}

@inlinable
public var endIndex: Int {
return changesets.endIndex
}

@inlinable
public func index(after i: Int) -> Int {
return changesets.index(after: i)
}

@inlinable
public subscript(position: Int) -> Changeset<Collection> {
get { return changesets[position] }
set { changesets[position] = newValue }
}

@inlinable
public mutating func replaceSubrange<C: Swift.Collection, R: RangeExpression>(_ subrange: R, with newElements: C) where C.Element == Changeset<Collection>, R.Bound == Int {
changesets.replaceSubrange(subrange, with: newElements)
}
}
#if compiler(<5.0) && compiler(>=4.0)
extension StagedChangeset: MutableCollection {}
#endif

extension StagedChangeset: Equatable where Collection: Equatable {
Expand Down

0 comments on commit f00a2f6

Please sign in to comment.