Skip to content

Commit

Permalink
feat: make system calls more parallel (closes #160)
Browse files Browse the repository at this point in the history
  • Loading branch information
louis.pontoise authored and lwouis committed Mar 10, 2020
1 parent e28c43f commit a29b39f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
15 changes: 15 additions & 0 deletions alt-tab-macos/api-wrappers/HelperExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,18 @@ extension NSGridView {
}
}
}

extension Array {
// forEach with each iteration run concurrently on the global queue
func forEachAsync(fn: @escaping (Element) -> Void) {
let group = DispatchGroup()
for element in self {
group.enter()
DispatchQueue.global(qos: .userInteractive).async(group: group) {
fn(element)
group.leave()
}
}
group.wait()
}
}
13 changes: 6 additions & 7 deletions alt-tab-macos/logic/Windows.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,16 @@ class Windows {

static func updateSpaces() {
let spacesMap = Spaces.allIdsAndIndexes()
for window in list {
list.forEachAsync { window in
let spaceIds = window.cgWindowId.spaces()
guard spaceIds.count > 0 else { continue }
if spaceIds.count > 1 {
if spaceIds.count == 1 {
window.spaceId = spaceIds.first!
window.spaceIndex = spacesMap.first { $0.0 == spaceIds.first! }!.1
} else if spaceIds.count > 1 {
window.spaceId = Spaces.currentSpaceId
window.spaceIndex = Spaces.currentSpaceIndex
window.isOnAllSpaces = true
continue
}
window.spaceId = spaceIds.first!
window.spaceIndex = spacesMap.first { $0.0 == spaceIds.first! }!.1
}
}

Expand All @@ -59,7 +58,7 @@ class Windows {
}

static func refreshAllThumbnails() {
for window in list {
list.forEachAsync { window in
window.refreshThumbnail()
}
}
Expand Down

0 comments on commit a29b39f

Please sign in to comment.