@@ -355,56 +355,6 @@ extension MutableSpan where Element: ~Copyable {
355355 }
356356}
357357
358- @available ( SwiftCompatibilitySpan 5 . 0 , * )
359- @_originallyDefinedIn ( module: " Swift;CompatibilitySpan " , SwiftCompatibilitySpan 6 . 2 )
360- extension MutableSpan where Element: BitwiseCopyable {
361-
362- /// Accesses the element at the specified position in the `Span`.
363- ///
364- /// - Parameter position: The offset of the element to access. `position`
365- /// must be greater or equal to zero, and less than `count`.
366- ///
367- /// - Complexity: O(1)
368- @_alwaysEmitIntoClient
369- public subscript( _ position: Index ) -> Element {
370- get {
371- _precondition ( indices. contains ( position) , " index out of bounds " )
372- return unsafe self[ unchecked: position]
373- }
374- @lifetime ( self : copy self )
375- set {
376- _precondition ( indices. contains ( position) , " index out of bounds " )
377- unsafe self[ unchecked: position] = newValue
378- }
379- }
380-
381- /// Accesses the element at the specified position in the `Span`.
382- ///
383- /// This subscript does not validate `position`; this is an unsafe operation.
384- ///
385- /// - Parameter position: The offset of the element to access. `position`
386- /// must be greater or equal to zero, and less than `count`.
387- ///
388- /// - Complexity: O(1)
389- @unsafe
390- @_alwaysEmitIntoClient
391- public subscript( unchecked position: Index ) -> Element {
392- get {
393- let offset = position&* MemoryLayout< Element> . stride
394- return unsafe _start( ) . loadUnaligned (
395- fromByteOffset: offset, as: Element . self
396- )
397- }
398- @lifetime ( self : copy self )
399- set {
400- let offset = position&* MemoryLayout< Element> . stride
401- unsafe _start( ) . storeBytes (
402- of: newValue, toByteOffset: offset, as: Element . self
403- )
404- }
405- }
406- }
407-
408358@available ( SwiftCompatibilitySpan 5 . 0 , * )
409359@_originallyDefinedIn ( module: " Swift;CompatibilitySpan " , SwiftCompatibilitySpan 6 . 2 )
410360extension MutableSpan where Element: ~ Copyable {
@@ -476,220 +426,6 @@ extension MutableSpan {
476426 unsafe $0. update ( repeating: repeatedValue, count: count)
477427 }
478428 }
479-
480- @_alwaysEmitIntoClient
481- @lifetime ( self : copy self )
482- public mutating func update< S: Sequence > (
483- from source: S
484- ) -> ( unwritten: S . Iterator , index: Index ) where S. Element == Element {
485- var iterator = source. makeIterator ( )
486- let index = update ( from: & iterator)
487- return ( iterator, index)
488- }
489-
490- @_alwaysEmitIntoClient
491- @lifetime ( self : copy self )
492- public mutating func update(
493- from elements: inout some IteratorProtocol < Element >
494- ) -> Index {
495- var index = 0
496- while index < _count {
497- guard let element = elements. next ( ) else { break }
498- unsafe self[ unchecked: index] = element
499- index &+= 1
500- }
501- return index
502- }
503-
504- @_alwaysEmitIntoClient
505- @lifetime ( self : copy self )
506- public mutating func update(
507- fromContentsOf source: some Collection < Element >
508- ) -> Index {
509- let updated = source. withContiguousStorageIfAvailable {
510- self . update ( fromContentsOf: unsafe Span( _unsafeElements: $0) )
511- }
512- if let updated {
513- return updated
514- }
515-
516- //TODO: use _copyContents here
517-
518- var iterator = source. makeIterator ( )
519- let index = update ( from: & iterator)
520- _precondition (
521- iterator. next ( ) == nil ,
522- " destination buffer view cannot contain every element from source. "
523- )
524- return index
525- }
526-
527- @_alwaysEmitIntoClient
528- @lifetime ( self : copy self )
529- public mutating func update( fromContentsOf source: Span < Element > ) -> Index {
530- guard !source. isEmpty else { return 0 }
531- _precondition (
532- source. count <= self . count,
533- " destination span cannot contain every element from source. "
534- )
535- unsafe _start( ) . withMemoryRebound (
536- to: Element . self, capacity: source. count
537- ) { dest in
538- unsafe source. withUnsafeBufferPointer {
539- unsafe dest. update ( from: $0. baseAddress!, count: $0. count)
540- }
541- }
542- return source. count
543- }
544-
545- @_alwaysEmitIntoClient
546- @lifetime ( self : copy self )
547- public mutating func update(
548- fromContentsOf source: borrowing MutableSpan < Element >
549- ) -> Index {
550- update ( fromContentsOf: source. span)
551- }
552- }
553-
554- @available ( SwiftCompatibilitySpan 5 . 0 , * )
555- @_originallyDefinedIn ( module: " Swift;CompatibilitySpan " , SwiftCompatibilitySpan 6 . 2 )
556- extension MutableSpan where Element: ~ Copyable {
557-
558- // @_alwaysEmitIntoClient
559- // public mutating func moveUpdate(
560- // fromContentsOf source: consuming OutputSpan<Element>
561- // ) -> Index {
562- // guard !source.isEmpty else { return 0 }
563- // _precondition(
564- // source.count <= self.count,
565- // "destination span cannot contain every element from source."
566- // )
567- // let buffer = unsafe source.relinquishBorrowedMemory()
568- // // we must now deinitialize the returned UMBP
569- // unsafe _start().moveInitializeMemory(
570- // as: Element.self, from: buffer.baseAddress!, count: buffer.count
571- // )
572- // return buffer.count
573- // }
574-
575- @_alwaysEmitIntoClient
576- @lifetime ( self : copy self )
577- public mutating func moveUpdate(
578- fromContentsOf source: UnsafeMutableBufferPointer < Element >
579- ) -> Index {
580- // let source = OutputSpan(_initializing: source, initialized: source.count)
581- // return self.moveUpdate(fromContentsOf: source)
582- unsafe withUnsafeMutableBufferPointer {
583- unsafe $0. moveUpdate ( fromContentsOf: source)
584- }
585- }
586- }
587-
588- @available ( SwiftCompatibilitySpan 5 . 0 , * )
589- @_originallyDefinedIn ( module: " Swift;CompatibilitySpan " , SwiftCompatibilitySpan 6 . 2 )
590- extension MutableSpan {
591-
592- @_alwaysEmitIntoClient
593- @lifetime ( self : copy self )
594- public mutating func moveUpdate(
595- fromContentsOf source: Slice < UnsafeMutableBufferPointer < Element > >
596- ) -> Index {
597- unsafe moveUpdate( fromContentsOf: . init( rebasing: source) )
598- }
599- }
600-
601- @available ( SwiftCompatibilitySpan 5 . 0 , * )
602- @_originallyDefinedIn ( module: " Swift;CompatibilitySpan " , SwiftCompatibilitySpan 6 . 2 )
603- extension MutableSpan where Element: BitwiseCopyable {
604-
605- @_alwaysEmitIntoClient
606- @lifetime ( self : copy self )
607- public mutating func update(
608- repeating repeatedValue: Element
609- ) where Element: BitwiseCopyable {
610- guard count > 0 else { return }
611- // rebind _start manually in order to avoid assumptions about alignment.
612- let rp = unsafe _start( ) . _rawValue
613- let binding = Builtin . bindMemory ( rp, count. _builtinWordValue, Element . self)
614- let rebound = unsafe UnsafeMutablePointer< Element > ( rp)
615- unsafe rebound. update ( repeating: repeatedValue, count: count)
616- Builtin . rebindMemory ( rp, binding)
617- }
618-
619- @_alwaysEmitIntoClient
620- @lifetime ( self : copy self )
621- public mutating func update< S: Sequence > (
622- from source: S
623- ) -> ( unwritten: S . Iterator , index: Index )
624- where S. Element == Element , Element: BitwiseCopyable {
625- var iterator = source. makeIterator ( )
626- let index = update ( from: & iterator)
627- return ( iterator, index)
628- }
629-
630- @_alwaysEmitIntoClient
631- @lifetime ( self : copy self )
632- public mutating func update(
633- from elements: inout some IteratorProtocol < Element >
634- ) -> Index {
635- var index = 0
636- while index < _count {
637- guard let element = elements. next ( ) else { break }
638- unsafe self[ unchecked: index] = element
639- index &+= 1
640- }
641- return index
642- }
643-
644- @_alwaysEmitIntoClient
645- @lifetime ( self : copy self )
646- public mutating func update(
647- fromContentsOf source: some Collection < Element >
648- ) -> Index where Element: BitwiseCopyable {
649- let updated = source. withContiguousStorageIfAvailable {
650- self . update ( fromContentsOf: unsafe Span( _unsafeElements: $0) )
651- }
652- if let updated {
653- return updated
654- }
655-
656- //TODO: use _copyContents here
657-
658- var iterator = source. makeIterator ( )
659- let index = update ( from: & iterator)
660- _precondition (
661- iterator. next ( ) == nil ,
662- " destination buffer view cannot contain every element from source. "
663- )
664- return index
665- }
666-
667- @_alwaysEmitIntoClient
668- @lifetime ( self : copy self )
669- public mutating func update(
670- fromContentsOf source: Span < Element >
671- ) -> Index where Element: BitwiseCopyable {
672- guard !source. isEmpty else { return 0 }
673- _precondition (
674- source. count <= self . count,
675- " destination span cannot contain every element from source. "
676- )
677- unsafe source. withUnsafeBufferPointer {
678- unsafe _start( ) . copyMemory (
679- from: $0. baseAddress!,
680- byteCount: $0. count &* MemoryLayout< Element> . stride
681- )
682- }
683- return source. count
684- }
685-
686- @_alwaysEmitIntoClient
687- @lifetime ( self : copy self )
688- public mutating func update(
689- fromContentsOf source: borrowing MutableSpan < Element >
690- ) -> Index where Element: BitwiseCopyable {
691- update ( fromContentsOf: source. span)
692- }
693429}
694430
695431// MARK: sub-spans
0 commit comments