Skip to content

[cxx-interop] Make some CxxSequence methods inlinable #61484

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 13, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions stdlib/public/Cxx/CxxSequence.swift
Original file line number Diff line number Diff line change
Expand Up @@ -85,16 +85,21 @@ public class CxxIterator<T>: IteratorProtocol where T: CxxSequence {
// which would result in dangling pointers for some C++ sequence types.

public typealias Element = T.RawIterator.Pointee
private var sequence: T
private var rawIterator: T.RawIterator
private let endIterator: T.RawIterator

@usableFromInline
internal var sequence: T
@usableFromInline
internal var rawIterator: T.RawIterator
@usableFromInline
internal let endIterator: T.RawIterator

public init(sequence: T) {
self.sequence = sequence
self.rawIterator = self.sequence.__beginUnsafe()
self.endIterator = self.sequence.__endUnsafe()
}

@inlinable
public func next() -> Element? {
if self.rawIterator == self.endIterator {
return nil
Expand All @@ -106,6 +111,7 @@ public class CxxIterator<T>: IteratorProtocol where T: CxxSequence {
}

extension CxxSequence {
@inlinable
public func makeIterator() -> CxxIterator<Self> {
return CxxIterator(sequence: self)
}
Expand Down