mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Merge pull request #65612 from eeckstein/inline-array-count
stdlib: force inlining of `ContiguousArray.endIndex` and `ContiguousArray._getCount`
This commit is contained in:
@@ -53,6 +53,7 @@ public struct ContiguousArray<Element>: _DestructorSafeContainer {
|
|||||||
//===--- private helpers---------------------------------------------------===//
|
//===--- private helpers---------------------------------------------------===//
|
||||||
extension ContiguousArray {
|
extension ContiguousArray {
|
||||||
@inlinable
|
@inlinable
|
||||||
|
@inline(__always)
|
||||||
@_semantics("array.get_count")
|
@_semantics("array.get_count")
|
||||||
internal func _getCount() -> Int {
|
internal func _getCount() -> Int {
|
||||||
return _buffer.immutableCount
|
return _buffer.immutableCount
|
||||||
@@ -204,6 +205,7 @@ extension ContiguousArray: RandomAccessCollection, MutableCollection {
|
|||||||
/// If the array is empty, `endIndex` is equal to `startIndex`.
|
/// If the array is empty, `endIndex` is equal to `startIndex`.
|
||||||
public var endIndex: Int {
|
public var endIndex: Int {
|
||||||
@inlinable
|
@inlinable
|
||||||
|
@inline(__always)
|
||||||
get {
|
get {
|
||||||
return _getCount()
|
return _getCount()
|
||||||
}
|
}
|
||||||
|
|||||||
20
test/SILOptimizer/array_loop.swift
Normal file
20
test/SILOptimizer/array_loop.swift
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
// 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
|
||||||
|
}
|
||||||
|
|
||||||
Reference in New Issue
Block a user