mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
SwiftCompilerSources: add a few utility APIs
This commit is contained in:
@@ -228,3 +228,16 @@ struct OperandSet : IntrusiveSet {
|
||||
context.freeOperandSet(bridged)
|
||||
}
|
||||
}
|
||||
|
||||
extension IntrusiveSet {
|
||||
mutating func insert(contentsOf source: some Sequence<Element>) {
|
||||
for element in source {
|
||||
_ = insert(element)
|
||||
}
|
||||
}
|
||||
|
||||
init(insertContentsOf source: some Sequence<Element>, _ context: some Context) {
|
||||
self.init(context)
|
||||
insert(contentsOf: source)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -150,6 +150,10 @@ extension Sequence where Element == Operand {
|
||||
self.lazy.filter { !($0.instruction is I) }
|
||||
}
|
||||
|
||||
public func ignore(user: Instruction) -> LazyFilterSequence<Self> {
|
||||
self.lazy.filter { !($0.instruction == user) }
|
||||
}
|
||||
|
||||
public func getSingleUser<I: Instruction>(ofType: I.Type) -> I? {
|
||||
filterUsers(ofType: I.self).singleUse?.instruction as? I
|
||||
}
|
||||
|
||||
@@ -98,6 +98,8 @@ public extension CollectionLikeSequence {
|
||||
}
|
||||
return singleElement
|
||||
}
|
||||
|
||||
var first: Element? { first(where: { _ in true }) }
|
||||
}
|
||||
|
||||
// Also make the lazy sequences a CollectionLikeSequence if the underlying sequence is one.
|
||||
|
||||
Reference in New Issue
Block a user