mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
stdlib: add a function to squeeze a number in a given range from a hash value
This function mixes the bits in the hash value, which improves Dictionary performance for keys with bad hashes. PrecommitBenchmark changes with greater than 7% difference: ``````````Dictionary2`,```1456.00`,```1508.00`,```1502.00`,````624.00`,````607.00`,````592.00`,`864.00`,``145.9% ``````````Dictionary3`,```1379.00`,```1439.00`,```1408.00`,````585.00`,````567.00`,````552.00`,`827.00`,``149.8% ````````````Histogram`,````850.00`,````849.00`,````851.00`,```1053.00`,```1049.00`,```1048.00`,`199.00`,``-19.0% ````````````````Prims`,```1999.00`,```2005.00`,```2018.00`,```1734.00`,```1689.00`,```1701.00`,`310.00`,```18.4% ``````````StrSplitter`,```2365.00`,```2334.00`,```2316.00`,```1979.00`,```1997.00`,```2000.00`,`337.00`,```17.0% ```````````````TwoSum`,```1551.00`,```1568.00`,```1556.00`,```1771.00`,```1741.00`,```1716.00`,`165.00`,```-9.6% Regressions are in benchmarks that use `Int` as dictionary key: we are just doing more work than previously (hashing an `Int` was an identity function). rdar://17962402 Swift SVN r21142
This commit is contained in:
@@ -235,6 +235,7 @@ public func assertionFailure() -> AssertionResult {
|
||||
public func expectTrue(
|
||||
actual: ${BoolType},
|
||||
stackTrace: SourceLocStack? = nil,
|
||||
_ collectMoreInfo: (()->String)? = nil,
|
||||
file: String = __FILE__, line: UWord = __LINE__
|
||||
) {
|
||||
if !actual {
|
||||
@@ -243,6 +244,7 @@ public func expectTrue(
|
||||
_printStackTrace(stackTrace)
|
||||
println("expected: true")
|
||||
println("actual: \(actual)")
|
||||
if collectMoreInfo != nil { println(collectMoreInfo!()) }
|
||||
println()
|
||||
}
|
||||
}
|
||||
@@ -250,6 +252,7 @@ public func expectTrue(
|
||||
public func expectFalse(
|
||||
actual: ${BoolType},
|
||||
stackTrace: SourceLocStack? = nil,
|
||||
_ collectMoreInfo: (()->String)? = nil,
|
||||
file: String = __FILE__, line: UWord = __LINE__
|
||||
) {
|
||||
if actual {
|
||||
@@ -258,6 +261,7 @@ public func expectFalse(
|
||||
_printStackTrace(stackTrace)
|
||||
println("expected: false")
|
||||
println("actual: \(actual)")
|
||||
if collectMoreInfo != nil { println(collectMoreInfo!()) }
|
||||
println()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user