mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[stdlib] add two-operand version of max and use max2 in stdlib when appropriate.
This helps array append's performance by ~ 2x. The generic max with a variadic argument creates a temporary array then iterates over the array. rdar://17140639 rdar://17073827 Swift SVN r18764
This commit is contained in:
@@ -312,6 +312,14 @@ func min<T : Comparable>(x: T, y: T, rest: T...) -> T {
|
||||
return r
|
||||
}
|
||||
|
||||
func max2<T : Comparable>(x: T, y: T) -> T {
|
||||
var r = y
|
||||
if y < x {
|
||||
r = x
|
||||
}
|
||||
return r
|
||||
}
|
||||
|
||||
func max<T : Comparable>(x: T, y: T, rest: T...) -> T {
|
||||
var r = y
|
||||
if y < x {
|
||||
|
||||
Reference in New Issue
Block a user