Skip to content

Commit 42d9c81

Browse files
committed
stdlib: SE-0065: make UnsafeMutableAudioBufferListPointer a random-access collection again
1 parent 651d9f9 commit 42d9c81

File tree

3 files changed

+33
-2
lines changed

3 files changed

+33
-2
lines changed

stdlib/public/SDK/CoreAudio/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
add_swift_library(swiftCoreAudio IS_SDK_OVERLAY
22
CoreAudio.swift
3+
../../../public/core/WriteBackMutableSlice.swift
34

45
TARGET_SDKS OSX IOS IOS_SIMULATOR TVOS TVOS_SIMULATOR
56
SWIFT_MODULE_DEPENDS Dispatch

stdlib/public/SDK/CoreAudio/CoreAudio.swift

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,11 @@ public struct UnsafeMutableAudioBufferListPointer {
128128

129129
// FIXME: swift-3-indexing-model: conform to RandomAccessCollection
130130
// and update the test to reflect the change.
131-
extension UnsafeMutableAudioBufferListPointer : MutableCollection {
131+
extension UnsafeMutableAudioBufferListPointer
132+
: MutableCollection, RandomAccessCollection {
133+
134+
public typealias Index = Int
135+
132136
/// Always zero, which is the index of the first `AudioBuffer`.
133137
public var startIndex: Int {
134138
return 0
@@ -152,5 +156,21 @@ extension UnsafeMutableAudioBufferListPointer : MutableCollection {
152156
(_audioBuffersPointer + index).pointee = newValue
153157
}
154158
}
159+
160+
public subscript(bounds: Range<Int>)
161+
-> MutableRandomAccessSlice<UnsafeMutableAudioBufferListPointer> {
162+
get {
163+
return MutableRandomAccessSlice(base: self, bounds: bounds)
164+
}
165+
set {
166+
_writeBackMutableSlice(&self, bounds: bounds, slice: newValue)
167+
}
168+
}
169+
170+
public typealias Indices = CountableRange<Int>
171+
172+
public var indices: Indices {
173+
return startIndex..<endIndex
174+
}
155175
}
156176

validation-test/stdlib/CoreAudio.swift

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,16 @@ CoreAudioTestSuite.test("AudioBufferList.allocate(maximumBuffers: Int)/trap/over
159159
AudioBufferList.allocate(maximumBuffers: Int.max)
160160
}
161161

162+
CoreAudioTestSuite.test("UnsafeMutableAudioBufferListPointer/AssociatedTypes") {
163+
typealias Subject = UnsafeMutableAudioBufferListPointer
164+
expectRandomAccessCollectionAssociatedTypes(
165+
collectionType: Subject.self,
166+
iteratorType: IndexingIterator<Subject>.self,
167+
subSequenceType: MutableRandomAccessSlice<Subject>.self,
168+
indexType: Int.self,
169+
indexDistanceType: Int.self,
170+
indicesType: CountableRange<Int>.self)
171+
}
162172

163173
CoreAudioTestSuite.test(
164174
"UnsafeMutableAudioBufferListPointer.init(_: UnsafeMutablePointer<AudioBufferList>)," +
@@ -284,7 +294,7 @@ CoreAudioTestSuite.test("UnsafeMutableAudioBufferListPointer/Collection") {
284294
}
285295

286296
// FIXME: use checkMutableRandomAccessCollection, when we have that function.
287-
checkForwardCollection(expected, ablPtrWrapper)
297+
checkRandomAccessCollection(expected, ablPtrWrapper)
288298
free(ablPtrWrapper.unsafeMutablePointer)
289299
}
290300

0 commit comments

Comments
 (0)