//===----------------------------------------------------------------------===// // // This source file is part of the Swift Collections open source project // // Copyright (c) 2024 - 2026 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 // // SPDX-License-Identifier: Apache-2.0 WITH Swift-exception // //===----------------------------------------------------------------------===// #if !COLLECTIONS_SINGLE_MODULE import InternalCollectionsUtilities #endif #if compiler(>=6.4) && UnstableContainersPreview @available(SwiftStdlib 5.0, *) extension Container where Self: ~Copyable & ~Escapable, Element: ~Copyable { @_alwaysEmitIntoClient internal func _spanwiseZip( with other: borrowing Other, by process: (Span, Span) throws(E) -> Bool ) throws(E) -> (Index, Other.Index) { var i = self.startIndex // End index of the current span in `self` var j = other.startIndex // End index of the current span in `other` var a: Span = .init() var b: Span = .init() var pi = i // Start index of the original span we're currently processing in `self` var pj = j // Start index of the original span we're currently processing in `other` var ca = 0 // Count of the original span we're currently processing in `self` var cb = 0 // Count of the original span we're currently processing in `other` loop: while true { if a.isEmpty { pi = i a = self.nextSpan(after: &i) ca = a.count } if b.isEmpty { pj = j b = other.nextSpan(after: &j) cb = b.count } if a.isEmpty || b.isEmpty { return ( (a.isEmpty ? i : self.index(pi, offsetBy: ca - a.count)), (b.isEmpty ? j : other.index(pj, offsetBy: cb - b.count))) } let c = Swift.min(a.count, b.count) guard try process(a._trim(first: c), b._trim(first: c)) else { return ( (a.isEmpty ? i : self.index(pi, offsetBy: c)), (b.isEmpty ? j : other.index(pj, offsetBy: c))) } } } } #endif