Skip to content

Commit

Permalink
Parallelize iterating over subpaths (realm#2475)
Browse files Browse the repository at this point in the history
This has a very small performance improvement on multi-core machines
  • Loading branch information
jpsim authored Nov 22, 2018
1 parent ea171fb commit d1109da
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Source/SwiftLintFramework/Extensions/Array+SwiftLint.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ extension Array {
return parallelMap(transform: transform).flatMap { $0 }
}

func parallelFlatMap<T>(transform: @escaping ((Element) -> T?)) -> [T] {
func parallelCompactMap<T>(transform: @escaping ((Element) -> T?)) -> [T] {
return parallelMap(transform: transform).compactMap { $0 }
}

Expand Down
10 changes: 4 additions & 6 deletions Source/SwiftLintFramework/Extensions/FileManager+SwiftLint.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,12 @@ extension FileManager: LintableFileManager {

#if os(Linux)
return enumerator(atPath: absolutePath)?.compactMap { element -> String? in
if let element = element as? String,
element.bridge().isSwiftFile() && (absolutePath + "/" + element).isFile {
return absolutePath.bridge().appendingPathComponent(element)
}
return nil
guard let element = element as? String, element.bridge().isSwiftFile() else { return nil }
let absoluteElementPath = absolutePath.bridge().appendingPathComponent(element)
return absoluteElementPath.isFile ? absoluteElementPath : nil
} ?? []
#else
return subpaths(atPath: absolutePath)?.compactMap { element -> String? in
return subpaths(atPath: absolutePath)?.parallelCompactMap { element -> String? in
guard element.bridge().isSwiftFile() else { return nil }
let absoluteElementPath = absolutePath.bridge().appendingPathComponent(element)
return absoluteElementPath.isFile ? absoluteElementPath : nil
Expand Down
2 changes: 1 addition & 1 deletion Source/SwiftLintFramework/Models/Linter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public struct Linter {
let superfluousDisableCommandRule = rules.first(where: {
$0 is SuperfluousDisableCommandRule
}) as? SuperfluousDisableCommandRule
let validationResults = rules.parallelFlatMap {
let validationResults = rules.parallelCompactMap {
$0.lint(file: self.file, regions: regions, benchmark: benchmark,
superfluousDisableCommandRule: superfluousDisableCommandRule,
compilerArguments: self.compilerArguments)
Expand Down

0 comments on commit d1109da

Please sign in to comment.