mirror of
https://github.com/apple/swift-collections
synced 2026-11-22 04:20:40 +00:00
* [BorrowingMapProducer] Fix skip(by:) hanging at end of iterator When a BorrowingMapProducer's Failure is not Never, skip(by:) drove a loop over nextSpan calls. Once the base iterator was exhausted, nextSpan kept returning an empty span (count == 0), so the counter never decremented and the loop ran forever. Add a guard that exits the loop when the span is empty, matching the skip(by:) contract: return with the remaining count when the iterator runs out of elements before n reaches 0. Adds a regression test that builds a RigidArray from a mapError+map chain. RigidArray.init(capacity:from:) calls _expectEnd, which exercises exactly the exhausted-iterator code path. Fixes #773 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * fix: guard InputSpan methods against nil base address in debug builds removeFirst(_:), prepend(repeating:count:), and consumePrefix(upTo:) each call _unsafeRawAddressOfSlot(uncheckedOffset:) before checking whether there is anything to do. That helper calls _start(), which calls _pointer.unsafelyUnwrapped and traps in debug builds when the base address is nil — which happens for InputSpan(), for empty ranges handed to consumeSubrange closures, and for SubrangeConsumer drains once the range is exhausted. Add an early return for the zero-work case in each method, the same pattern that removeAll() and deinit already use. Release builds were unaffected in practice because unsafelyUnwrapped skips the nil check under -O, but the behaviour is formally undefined; this fix makes both build modes consistent and safe. Fixes #788 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * Resolve conflict Co-authored-by: Karoy Lorentey <klorentey@apple.com> * Prefer guard for succinct exit conditionals This follows our preferred coding style, and also syncs this code with OutputSpan's implementation in the stdlib. Co-authored-by: Karoy Lorentey <klorentey@apple.com> --------- Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com> Co-authored-by: Karoy Lorentey <klorentey@apple.com>