File tree Expand file tree Collapse file tree 3 files changed +14
-6
lines changed
Expand file tree Collapse file tree 3 files changed +14
-6
lines changed Original file line number Diff line number Diff line change @@ -63,6 +63,9 @@ public struct PrefixTextStyle<Base: DiffableTextStyle>: WrapperTextStyle {
6363 text = prefix + text
6464 }
6565
66+ /// This transformation assumes that the base style
67+ /// provides a manual selection when all attributes
68+ /// are passtrough, to avoid duplicate computations.
6669 @inlinable func label( _ snapshot: inout Snapshot ) {
6770 //=--------------------------------------=
6871 // None
@@ -86,10 +89,12 @@ public struct PrefixTextStyle<Base: DiffableTextStyle>: WrapperTextStyle {
8689 // Base x Some x Selection
8790 //=--------------------------------------=
8891 guard let selection = base. selection else { return }
89- let offsets = selection. map ( { size + $0. attribute } )
90- let lower = snapshot. index ( snapshot. startIndex, offsetBy: offsets. lower)
91- let upper = snapshot. index ( lower, offsetBy: offsets. upper - offsets. lower)
92- snapshot. select ( Range ( uncheckedBounds: ( lower, upper) ) )
92+ let min = selection. lower. attribute + size // offset
93+ let max = selection. upper. attribute + size // offset
94+
95+ let lower = snapshot. index ( snapshot. startIndex, offsetBy: min)
96+ let upper = snapshot. index ( lower, /*---*/ offsetBy: max - min)
97+ snapshot. select ( Range ( uncheckedBounds: ( lower, upper) ) ) /*--*/
9398 }
9499}
95100
Original file line number Diff line number Diff line change @@ -59,6 +59,9 @@ public struct SuffixTextStyle<Base: DiffableTextStyle>: WrapperTextStyle {
5959 text. append ( contentsOf: suffix)
6060 }
6161
62+ /// This transformation assumes that the base style
63+ /// provides a manual selection when all attributes
64+ /// are passtrough, to avoid duplicate computations.
6265 @inlinable func label( _ snapshot: inout Snapshot ) {
6366 //=--------------------------------------=
6467 // Base x None
Original file line number Diff line number Diff line change 1414public extension Sequence {
1515
1616 @inlinable func count( where predicate: ( Element ) throws -> Bool ) rethrows -> Int {
17- var S0 = 0 ; for x in self { if try predicate ( x ) { S0 += 1 } } ; return S0
17+ var S0 = 0 ; for S1 in self { if try predicate ( S1 ) { S0 += 1 } } ; return S0
1818 }
1919
2020 @inlinable func count( while predicate: ( Element ) throws -> Bool ) rethrows -> Int {
21- var S0 = 0 ; for x in self { if try predicate ( x ) { S0 += 1 } else { break } } ; return S0
21+ var S0 = 0 ; for S1 in self { if try predicate ( S1 ) { S0 += 1 } else { break } } ; return S0
2222 }
2323}
You can’t perform that action at this time.
0 commit comments