Skip to content

Commit bd354fd

Browse files
committed
Merge remote-tracking branch 'origin/master' into master-next
2 parents 3c9b7a4 + 739169d commit bd354fd

File tree

2 files changed

+15
-18
lines changed

2 files changed

+15
-18
lines changed

stdlib/public/core/ArrayCast.swift

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ internal func _arrayDownCastIndirect<SourceValue, TargetValue>(
2828
///
2929
/// - Note: When SourceElement and TargetElement are both bridged verbatim, type
3030
/// checking is deferred until elements are actually accessed.
31-
@inlinable // FIXME(sil-serialize-all)
31+
@inlinable //for performance reasons
3232
public func _arrayForceCast<SourceElement, TargetElement>(
3333
_ source: Array<SourceElement>
3434
) -> Array<TargetElement> {
@@ -52,21 +52,6 @@ public func _arrayForceCast<SourceElement, TargetElement>(
5252
return source.map { $0 as! TargetElement }
5353
}
5454

55-
@_fixed_layout
56-
@usableFromInline
57-
internal struct _UnwrappingFailed : Error {
58-
@inlinable
59-
internal init() {}
60-
}
61-
62-
extension Optional {
63-
@inlinable // FIXME(sil-serialize-all)
64-
internal func unwrappedOrError() throws -> Wrapped {
65-
if let x = self { return x }
66-
throw _UnwrappingFailed()
67-
}
68-
}
69-
7055
/// Called by the casting machinery.
7156
@_silgen_name("_swift_arrayDownCastConditionalIndirect")
7257
internal func _arrayDownCastConditionalIndirect<SourceValue, TargetValue>(
@@ -85,9 +70,18 @@ internal func _arrayDownCastConditionalIndirect<SourceValue, TargetValue>(
8570
/// return `nil` if any element fails to convert.
8671
///
8772
/// - Complexity: O(n), because each element must be checked.
88-
@inlinable // FIXME(sil-serialize-all)
73+
@inlinable //for performance reasons
8974
public func _arrayConditionalCast<SourceElement, TargetElement>(
9075
_ source: [SourceElement]
9176
) -> [TargetElement]? {
92-
return try? source.map { try ($0 as? TargetElement).unwrappedOrError() }
77+
var successfulCasts = ContiguousArray<TargetElement>()
78+
successfulCasts.reserveCapacity(source.count)
79+
for element in source {
80+
if let casted = element as? TargetElement {
81+
successfulCasts.append(casted)
82+
} else {
83+
return nil
84+
}
85+
}
86+
return Array(successfulCasts)
9387
}

test/api-digester/Outputs/stability-stdlib-abi.swift.expected

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ Func _int64ToStringImpl(_:_:_:_:_:) has been removed
1616
Func _uint64ToStringImpl(_:_:_:_:_:) has been removed
1717
Func _withUninitializedString(_:) has been removed
1818

19+
Func Optional.unwrappedOrError() has been removed
20+
Struct _UnwrappingFailed has been removed
21+
1922
Class _stdlib_AtomicInt has been removed
2023
Func _stdlib_atomicCompareExchangeStrongInt(object:expected:desired:) has been removed
2124
Func _stdlib_atomicCompareExchangeStrongInt32(object:expected:desired:) has been removed

0 commit comments

Comments
 (0)