mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
This let the optimizer generate efficient code for generic array loops (note that generic functions are not inlined by default). Note that the same change is not done for `Array` because this might increase code size due to Array's bridging code. rdar://108746069
21 lines
805 B
Swift
21 lines
805 B
Swift
// RUN: %target-swift-frontend -O -module-name=test -emit-sil -primary-file %s | %FileCheck %s
|
|
|
|
// REQUIRES: swift_stdlib_no_asserts
|
|
// REQUIRES: swift_in_compiler
|
|
|
|
|
|
// Test that even with a generic array the iteration is done efficiently.
|
|
|
|
// CHECK-LABEL: sil @$s4test0A15ContiguousArrayySis0bC0VyxG_SixXEtlF : $@convention(thin) <Element> (@guaranteed ContiguousArray<Element>, @guaranteed @noescape @callee_guaranteed @substituted <τ_0_0> (@in_guaranteed τ_0_0) -> Int for <Element>) -> Int {
|
|
// CHECK-NOT: function_ref
|
|
// CHECK-NOT: method
|
|
// CHECK: } // end sil function '$s4test0A15ContiguousArrayySis0bC0VyxG_SixXEtlF'
|
|
public func testContiguousArray<Element>(_ a: ContiguousArray<Element>, _ c: (Element) -> Int) -> Int {
|
|
var s = 0
|
|
for x in a {
|
|
s += c(x)
|
|
}
|
|
return s
|
|
}
|
|
|