Skip to content

Commit 74f5211

Browse files
rjchatfieldstephencelis
authored andcommitted
Faster sort function (#195)
Found a small change of building an array of snaps, *then* sorting them, it reduced on of our test cases from 6m 8s to just 9s. And noticed it crept over 2GB of memory usage.
1 parent 5ae8db2 commit 74f5211

File tree

1 file changed

+6
-1
lines changed
  • Sources/SnapshotTesting/Snapshotting

1 file changed

+6
-1
lines changed

Sources/SnapshotTesting/Snapshotting/Any.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,12 @@ private func snap<T>(_ value: T, name: String? = nil, indent: Int = 0) -> String
5555
}
5656

5757
private func sort(_ children: Mirror.Children) -> Mirror.Children {
58-
return .init(children.sorted { snap($0) < snap($1) })
58+
return .init(
59+
children
60+
.map({ (child: $0, snap: snap($0)) })
61+
.sorted(by: { $0.snap < $1.snap })
62+
.map({ $0.child })
63+
)
5964
}
6065

6166
/// A type with a customized snapshot dump representation.

0 commit comments

Comments
 (0)