Skip to content

Commit

Permalink
Use a filtered array instead of NSOrderedSet
Browse files Browse the repository at this point in the history
  • Loading branch information
Uncommon committed Dec 14, 2020
1 parent 33c3708 commit 10ecc0a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
15 changes: 8 additions & 7 deletions Xit/HistoryView/CommitHistory.swift
Original file line number Diff line number Diff line change
Expand Up @@ -254,17 +254,18 @@ public class CommitHistory<ID: OID & Hashable>: NSObject
connections: [CommitConnection<ID>])
{
var nextChildIndex: UInt = 0
let parentOutlets = NSOrderedSet(array: connections.compactMap {
($0.parentOID.equals(entry.commit.oid)) ? nil : $0.parentOID })
let parentOutlets = connections.compactMap {
($0.parentOID.equals(entry.commit.oid)) ? nil : $0.parentOID }.unique()
var parentLines: [ID: (childIndex: UInt,
colorIndex: UInt)] = [:]
var generatedLines: [HistoryLine] = []

for connection in connections {
let commitIsParent = connection.parentOID.equals(entry.commit.oid)
let commitIsChild = connection.childOID.equals(entry.commit.oid)
let parentIndex: UInt? = commitIsParent
? nil : self.parentIndex(parentOutlets, of: connection.parentOID)
let parentIndexInt = commitIsParent
? nil : parentOutlets.firstIndex(of: connection.parentOID)
let parentIndex = parentIndexInt.map { UInt($0) }
var childIndex: UInt? = commitIsChild
? nil : nextChildIndex
var colorIndex = connection.colorIndex
Expand Down Expand Up @@ -298,9 +299,9 @@ public class CommitHistory<ID: OID & Hashable>: NSObject
parentIndex: parentIndex,
colorIndex: colorIndex))
}
objc_sync_enter(self)
entry.lines.append(contentsOf: generatedLines)
objc_sync_exit(self)
withSync {
entry.lines.append(contentsOf: generatedLines)
}
}
}

Expand Down
10 changes: 10 additions & 0 deletions Xit/Utils/MiscExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,16 @@ extension Array where Element: Comparable
}
}

extension Sequence where Iterator.Element: Hashable
{
func unique() -> [Iterator.Element]
{
var seen: Set<Iterator.Element> = []

return filter { seen.insert($0).inserted }
}
}

extension NSMutableArray
{
func sort(keyPath key: String, ascending: Bool = true)
Expand Down

0 comments on commit 10ecc0a

Please sign in to comment.