Skip to content

Commit 509b9ce

Browse files
authored
Merge pull request #7 from SwiftRex/buildTimeFixes
Reduce build time by a few milliseconds
2 parents 133dcdc + b42b3c8 commit 509b9ce

File tree

3 files changed

+15
-8
lines changed

3 files changed

+15
-8
lines changed

Package.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ let package = Package(
2020
dependencies: [
2121
.product(name: "CombineRex", package: "SwiftRex")
2222
]
23+
// Enable this for build performance warnings. Works only when building the Package, works not when building the workspace! Obey the comma.
24+
// , swiftSettings: [SwiftSetting.unsafeFlags(["-Xfrontend", "-warn-long-expression-type-checking=10", "-Xfrontend", "-warn-long-function-bodies=10"])]
25+
2326
),
2427
.testTarget(name: "LoggerMiddlewareTests", dependencies: ["LoggerMiddleware"])
2528
]

Sources/LoggerMiddleware/Diff.swift

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,17 @@ public struct Difference<A> {
2020
extension Difference where A == String {
2121
public static func diff(old: String, new: String, linesOfContext: Int, prefixLines: String = "") -> String? {
2222
guard old != new else { return nil }
23-
let oldSplit = old.split(separator: "\n", omittingEmptySubsequences: false).map(String.init)
24-
let newSplit = new.split(separator: "\n", omittingEmptySubsequences: false).map(String.init)
23+
let oldSplit: [String] = old.split(separator: "\n", omittingEmptySubsequences: false).map(String.init)
24+
let newSplit: [String] = new.split(separator: "\n", omittingEmptySubsequences: false).map(String.init)
2525

2626
return chunk(
2727
diff: Difference.diff(oldSplit, newSplit),
2828
context: linesOfContext
29-
).lazy.flatMap { [$0.patchMark] + $0.lines }.map { "\(prefixLines)\($0)" }.joined(separator: "\n")
29+
)
30+
.lazy
31+
.flatMap { (hunk: Hunk) -> [String] in [hunk.patchMark] + hunk.lines }
32+
.map { (line: String) -> String in "\(prefixLines)\(line)" }
33+
.joined(separator: "\n")
3034
}
3135
}
3236

Sources/LoggerMiddleware/LoggerMiddleware.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ extension LoggerMiddleware {
121121
}
122122

123123
private static func fileLog(state: String, to fileURL: URL) {
124-
try? state.write(toFile: fileURL.absoluteString, atomically: false, encoding: .utf8)
124+
try? state.write(toFile: fileURL.absoluteString, atomically: false, encoding: String.Encoding.utf8)
125125
}
126126
}
127127

@@ -189,8 +189,8 @@ extension LoggerMiddleware {
189189

190190
// special handling for sets as well: order the contents, compare as strings
191191
if let left = leftHandSide as? Set<AnyHashable>, let right = rightHandSide as? Set<AnyHashable> {
192-
let leftSorted = left.map { "\($0)" }.sorted { a, b in a < b }
193-
let rightSorted = right.map { "\($0)" }.sorted { a, b in a < b }
192+
let leftSorted: [String] = left.map { (lft: AnyHashable) in "\(lft)" }.sorted { a, b in a < b }
193+
let rightSorted: [String] = right.map { (rgt: AnyHashable) in "\(rgt)" }.sorted { a, b in a < b }
194194

195195
let leftPrintable = leftSorted.joined(separator: ", ")
196196
let rightPrintable = rightSorted.joined(separator: ", ")
@@ -215,7 +215,7 @@ extension LoggerMiddleware {
215215
}
216216

217217
// there are children -> diff the object graph recursively
218-
let strings: [String] = leftMirror.children.map({ leftChild in
218+
let strings: [String] = leftMirror.children.map({ (leftChild: Mirror.Child) -> String? in
219219
let toDotOrNotToDot = (level > 0) ? "." : " "
220220
return Self.diff(prefix: "\(prefix)\(toDotOrNotToDot)\(name)",
221221
name: leftChild.label ?? "#", // label might be missing for items in collections, # represents a collection element
@@ -227,7 +227,7 @@ extension LoggerMiddleware {
227227
.compactMap { $0 }
228228
.filter { (diffLine: String) -> Bool in
229229
// filter diffLine if it contains a filterString
230-
false == (filters ?? []).contains(where: { filterString in
230+
false == (filters ?? []).contains(where: { (filterString: String) -> Bool in
231231
diffLine.contains(filterString)
232232
})
233233
}

0 commit comments

Comments
 (0)