Guillaume Lessard fe89db476a
remove dependsOn parameter
- it is not useful without compiler support.
2023-04-04 17:02:31 -07:00

41 lines
1.3 KiB
Swift

//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2023 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//
@frozen @usableFromInline
internal struct BufferViewIterator<Element>{
var curPointer: UnsafeRawPointer
let endPointer: UnsafeRawPointer
init(startPointer: UnsafeRawPointer, endPointer: UnsafeRawPointer) {
self.curPointer = startPointer
self.endPointer = endPointer
}
init(from start: BufferViewIndex<Element>, to end: BufferViewIndex<Element>) {
self.init(startPointer: start._rawValue, endPointer: end._rawValue)
}
}
extension BufferViewIterator: IteratorProtocol {
public mutating func next() -> Element? {
guard curPointer < endPointer else { return nil }
defer {
curPointer = curPointer.advanced(by: MemoryLayout<Element>.stride)
}
if _isPOD(Element.self) {
return curPointer.loadUnaligned(as: Element.self)
}
return curPointer.load(as: Element.self)
}
}