@@ -18,6 +18,7 @@ public extension StagedChangeset where Collection: RangeReplaceableCollection, C
1818 /// - target: A target collection to calculate differences.
1919 ///
2020 /// - Complexity: O(n)
21+ @inlinable
2122 public init ( source: Collection , target: Collection ) {
2223 self . init ( source: source, target: target, section: 0 )
2324 }
@@ -42,6 +43,7 @@ public extension StagedChangeset where Collection: RangeReplaceableCollection, C
4243 /// - section: An Int value to use as section index (or offset) of element.
4344 ///
4445 /// - Complexity: O(n)
46+ @inlinable
4547 public init ( source: Collection , target: Collection , section: Int ) {
4648 let sourceElements = ContiguousArray ( source)
4749 let targetElements = ContiguousArray ( target)
@@ -134,6 +136,7 @@ public extension StagedChangeset where Collection: RangeReplaceableCollection, C
134136 /// - target: A target sectioned collection to calculate differences.
135137 ///
136138 /// - Complexity: O(n)
139+ @inlinable
137140 public init ( source: Collection , target: Collection ) {
138141 typealias Section = Collection . Element
139142 typealias SectionIdentifier = Collection . Element . DifferenceIdentifier
@@ -405,8 +408,9 @@ public extension StagedChangeset where Collection: RangeReplaceableCollection, C
405408}
406409
407410/// The shared algorithm to calculate differences between two linear collections.
411+ @inlinable
408412@discardableResult
409- private func differentiate< E: Differentiable , I> (
413+ internal func differentiate< E: Differentiable , I> (
410414 source: ContiguousArray < E > ,
411415 target: ContiguousArray < E > ,
412416 trackTargetIndexAsUpdated: Bool ,
@@ -528,16 +532,23 @@ private func differentiate<E: Differentiable, I>(
528532}
529533
530534/// A set of changes and metadata as a result of calculating differences in linear collection.
531- private struct DifferentiateResult < Index> {
532- typealias Metadata = ( sourceTraces: ContiguousArray < Trace < Int > > , targetReferences: ContiguousArray < Int ? > )
533-
534- let deleted : [ Index ]
535- let inserted : [ Index ]
536- let updated : [ Index ]
537- let moved : [ ( source: Index , target: Index ) ]
538- let metadata : Metadata
539-
540- init (
535+ @usableFromInline
536+ internal struct DifferentiateResult < Index> {
537+ @usableFromInline
538+ internal typealias Metadata = ( sourceTraces: ContiguousArray < Trace < Int > > , targetReferences: ContiguousArray < Int ? > )
539+ @usableFromInline
540+ internal let deleted : [ Index ]
541+ @usableFromInline
542+ internal let inserted : [ Index ]
543+ @usableFromInline
544+ internal let updated : [ Index ]
545+ @usableFromInline
546+ internal let moved : [ ( source: Index , target: Index ) ]
547+ @usableFromInline
548+ internal let metadata : Metadata
549+
550+ @inlinable
551+ internal init (
541552 deleted: [ Index ] = [ ] ,
542553 inserted: [ Index ] = [ ] ,
543554 updated: [ Index ] = [ ] ,
@@ -553,32 +564,46 @@ private struct DifferentiateResult<Index> {
553564}
554565
555566/// A set of informations in middle of difference calculation.
556- private struct Trace < Index> {
557- var reference : Index ?
558- var deleteOffset = 0
559- var isTracked = false
567+ @usableFromInline
568+ internal struct Trace < Index> {
569+ @usableFromInline
570+ internal var reference : Index ?
571+ @usableFromInline
572+ internal var deleteOffset = 0
573+ @usableFromInline
574+ internal var isTracked = false
575+
576+ @inlinable
577+ init ( ) { }
560578}
561579
562580/// The occurrences of element.
563- private enum Occurrence {
581+ @usableFromInline
582+ internal enum Occurrence {
564583 case unique( index: Int )
565584 case duplicate( reference: IndicesReference )
566585}
567586
568587/// A mutable reference to indices of elements.
569- private final class IndicesReference {
570- private var indices : ContiguousArray < Int >
571- private var position = 0
572-
573- init ( _ indices: ContiguousArray < Int > ) {
588+ @usableFromInline
589+ internal final class IndicesReference {
590+ @usableFromInline
591+ internal var indices : ContiguousArray < Int >
592+ @usableFromInline
593+ internal var position = 0
594+
595+ @inlinable
596+ internal init ( _ indices: ContiguousArray < Int > ) {
574597 self . indices = indices
575598 }
576599
577- func push( _ index: Int ) {
600+ @inlinable
601+ internal func push( _ index: Int ) {
578602 indices. append ( index)
579603 }
580604
581- func next( ) -> Int ? {
605+ @inlinable
606+ internal func next( ) -> Int ? {
582607 guard position < indices. endIndex else {
583608 return nil
584609 }
@@ -588,23 +613,29 @@ private final class IndicesReference {
588613}
589614
590615/// Dictionary key using UnsafePointer for performance optimization.
591- private struct TableKey < T: Hashable > : Hashable {
592- let hashValue : Int
593- private let pointer : UnsafePointer < T >
594-
595- init ( pointer: UnsafePointer < T > ) {
616+ @usableFromInline
617+ internal struct TableKey < T: Hashable > : Hashable {
618+ @usableFromInline
619+ internal let hashValue : Int
620+ @usableFromInline
621+ internal let pointer : UnsafePointer < T >
622+
623+ @inlinable
624+ internal init ( pointer: UnsafePointer < T > ) {
596625 self . hashValue = pointer. pointee. hashValue
597626 self . pointer = pointer
598627 }
599628
600- static func == ( lhs: TableKey , rhs: TableKey ) -> Bool {
629+ @inlinable
630+ internal static func == ( lhs: TableKey , rhs: TableKey ) -> Bool {
601631 return lhs. hashValue == rhs. hashValue
602632 && ( lhs. pointer. distance ( to: rhs. pointer) == 0 || lhs. pointer. pointee == rhs. pointer. pointee)
603633 }
604634}
605635
606- private extension MutableCollection where Element: MutableCollection , Index == Int , Element. Index == Int {
607- subscript( path: ElementPath ) -> Element . Element {
636+ internal extension MutableCollection where Element: MutableCollection , Index == Int , Element. Index == Int {
637+ @inlinable
638+ internal subscript( path: ElementPath ) -> Element . Element {
608639 get { return self [ path. section] [ path. element] }
609640 set { self [ path. section] [ path. element] = newValue }
610641 }
0 commit comments