From c12c6b90f508baba754e3939f2f2ae595890f0d5 Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Tue, 20 Aug 2019 13:42:22 -0400 Subject: [PATCH] use index functions instead of counters --- .../desktop/safari/SafariExtensionViewController.swift | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/safari/app/desktop/safari/SafariExtensionViewController.swift b/src/safari/app/desktop/safari/SafariExtensionViewController.swift index 2b41726cbb..3549916720 100644 --- a/src/safari/app/desktop/safari/SafariExtensionViewController.swift +++ b/src/safari/app/desktop/safari/SafariExtensionViewController.swift @@ -178,36 +178,34 @@ func processWindowsForTabs(wins: [SFSafariWindow], options: TabQueryOptions?, co } var newTabs: [Tab] = [] let winGroup = DispatchGroup() - var windowIndex = 0 for win in wins { winGroup.enter() win.getActiveTab { activeTab in win.getAllTabs { allTabs in let tabGroup = DispatchGroup() - var tabIndex = 0 for tab in allTabs { tabGroup.enter() if options?.active ?? false { if activeTab != nil && activeTab == tab { + let windowIndex = wins.firstIndex(of: win) ?? -100 + let tabIndex = allTabs.firstIndex(of: tab) ?? -1 makeTabObject(tab: tab, activeTab: activeTab, windowIndex: windowIndex, tabIndex: tabIndex, complete: { t in newTabs.append(t) - tabIndex = tabIndex + 1 tabGroup.leave() }) } else { - tabIndex = tabIndex + 1 tabGroup.leave() } } else { + let windowIndex = wins.firstIndex(of: win) ?? -100 + let tabIndex = allTabs.firstIndex(of: tab) ?? -1 makeTabObject(tab: tab, activeTab: activeTab, windowIndex: windowIndex, tabIndex: tabIndex, complete: { t in newTabs.append(t) - tabIndex = tabIndex + 1 tabGroup.leave() }) } } tabGroup.notify(queue: .main) { - windowIndex = windowIndex + 1 winGroup.leave() } }