Skip to content

Commit c083db5

Browse files
committed
Restore deterministic shrinking for UnicodeScalar
nub changes the order of the shrink from run to run and is probably less efficient than tail-allocating these arrays
1 parent c0f577d commit c083db5

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

Sources/SwiftCheck/Arbitrary.swift

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,12 @@ extension UnicodeScalar : Arbitrary {
303303
/// The default shrinking function for `UnicodeScalar` values.
304304
public static func shrink(_ x : UnicodeScalar) -> [UnicodeScalar] {
305305
let s : UnicodeScalar = UnicodeScalar(UInt32(tolower(Int32(x.value))))!
306-
return [ "a", "b", "c", s, "A", "B", "C", "1", "2", "3", "\n", " " ].nub.filter { $0 < x }
306+
let scalarSet = Set<UnicodeScalar>([ "a", "b", "c", "A", "B", "C", "1", "2", "3", "\n", " " ])
307+
if scalarSet.contains(s) {
308+
return [ "a", "b", "c", "A", "B", "C", "1", "2", "3", "\n", " " ].filter { $0 < x }
309+
} else {
310+
return [ "a", "b", "c", s, "A", "B", "C", "1", "2", "3", "\n", " " ].filter { $0 < x }
311+
}
307312
}
308313
}
309314

@@ -365,14 +370,6 @@ extension Mirror : Arbitrary {
365370
}
366371
}
367372

368-
369-
// MARK: - Implementation Details Follow
370-
371-
extension Array where Element : Hashable {
372-
fileprivate var nub : [Element] {
373-
return [Element](Set(self))
374-
}
375-
}
376373
#if os(Linux)
377374
import Glibc
378375
#else

0 commit comments

Comments
 (0)