Skip to content

Commit 8f9a628

Browse files
committed
Cleanup.
1 parent 5bce9ad commit 8f9a628

File tree

7 files changed

+35
-130
lines changed

7 files changed

+35
-130
lines changed

Sources/DiffableTextKit/Models/Changes.swift

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,32 +8,23 @@
88
//=----------------------------------------------------------------------------=
99

1010
//*============================================================================*
11-
// MARK: * Changes
11+
// MARK: * Changes [...]
1212
//*============================================================================*
1313

1414
/// A model used to capture comparison results.
1515
@frozen @usableFromInline struct Changes: OptionSet {
1616

1717
//=------------------------------------------------------------------------=
18-
// MARK: Instances
19-
//=------------------------------------------------------------------------=
2018

2119
public static let style = Self(rawValue: 1 << 0)
2220
public static let value = Self(rawValue: 1 << 1)
2321
public static let focus = Self(rawValue: 1 << 2)
2422

25-
//=------------------------------------------------------------------------=
26-
// MARK: State
2723
//=------------------------------------------------------------------------=
2824

2925
public var rawValue: UInt8
3026

31-
//=------------------------------------------------------------------------=
32-
// MARK: Initializers
3327
//=------------------------------------------------------------------------=
3428

35-
@inlinable @inline(__always)
36-
public init(rawValue: UInt8) {
37-
self.rawValue = rawValue
38-
}
29+
@inlinable init(rawValue: UInt8) { self.rawValue = rawValue }
3930
}

Sources/DiffableTextKit/Models/Commit.swift

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,39 +8,27 @@
88
//=----------------------------------------------------------------------------=
99

1010
//*============================================================================*
11-
// MARK: * Commit
11+
// MARK: * Commit [...]
1212
//*============================================================================*
1313

1414
/// A value and a snapshot describing it.
1515
public struct Commit<Value: Equatable>: Equatable {
1616

1717
//=------------------------------------------------------------------------=
18-
// MARK: State
19-
//=------------------------------------------------------------------------=
2018

2119
public var value: Value
2220
public var snapshot: Snapshot
2321

24-
//=------------------------------------------------------------------------=
25-
// MARK: Initializers
2622
//=------------------------------------------------------------------------=
2723

2824
@inlinable public init(_ value: Value, _ snapshot: Snapshot) {
2925
self.value = value; self.snapshot = snapshot
3026
}
3127

32-
//=------------------------------------------------------------------------=
33-
// MARK: Initializers
34-
//=------------------------------------------------------------------------=
35-
3628
@inlinable public init() where Value: RangeReplaceableCollection {
3729
self.init(Value(), Snapshot())
3830
}
3931

40-
//=------------------------------------------------------------------------=
41-
// MARK: Initializers
42-
//=------------------------------------------------------------------------=
43-
4432
@inlinable public init<T>() where Value == Optional<T> {
4533
self.init(nil, Snapshot())
4634
}

Sources/DiffableTextKit/Models/Index.swift

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,17 @@
88
//=----------------------------------------------------------------------------=
99

1010
//*============================================================================*
11-
// MARK: * Index
11+
// MARK: * Index [...]
1212
//*============================================================================*
1313

1414
/// A character encoded index and offset.
15-
public struct Index: Comparable {
15+
public struct Index: Comparable, CustomStringConvertible {
1616

1717
//=------------------------------------------------------------------------=
18-
// MARK: State
19-
//=------------------------------------------------------------------------=
2018

2119
@usableFromInline let character: String.Index
2220
@usableFromInline let attribute: Int
2321

24-
//=------------------------------------------------------------------------=
25-
// MARK: Initializers
2622
//=------------------------------------------------------------------------=
2723

2824
/// Creates an instance describing a character's position.
@@ -37,9 +33,9 @@ public struct Index: Comparable {
3733
self.attribute = attribute
3834
}
3935

40-
//=------------------------------------------------------------------------=
41-
// MARK: Utilities
42-
//=------------------------------------------------------------------------=
36+
public var description: String {
37+
String(describing: attribute)
38+
}
4339

4440
@inlinable @inline(__always)
4541
public static func == (lhs: Self, rhs: Self) -> Bool {

Sources/DiffableTextKit/Models/Offset.swift

Lines changed: 12 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -89,31 +89,17 @@ AdditiveArithmetic, ExpressibleByIntegerLiteral {
8989
}
9090

9191
//*============================================================================*
92-
// MARK: * Offset x Int
92+
// MARK: * Offset x Int [...]
9393
//*============================================================================*
9494

95-
public extension Int {
96-
97-
//=------------------------------------------------------------------------=
98-
// MARK: Initializers
99-
//=------------------------------------------------------------------------=
100-
101-
@inlinable @inline(__always)
102-
init<T>(_ offset: Offset<T>) {
103-
self = offset.distance
104-
}
105-
}
95+
public extension Int { @inlinable init<T>(_ offset: Offset<T>) { self = offset.distance } }
10696

10797
//*============================================================================*
108-
// MARK: * Offsets
98+
// MARK: * Offsets [...]
10999
//*============================================================================*
110100

111101
public protocol Offsets<Index>: Collection {
112102

113-
//=------------------------------------------------------------------------=
114-
// MARK: Utilities
115-
//=------------------------------------------------------------------------=
116-
117103
@inlinable @inline(__always) func distance<T>(
118104
from start: Index, to end: Index) -> Offset<T>
119105

@@ -122,15 +108,11 @@ public protocol Offsets<Index>: Collection {
122108
}
123109

124110
//=----------------------------------------------------------------------------=
125-
// MARK: + Details
111+
// MARK: + Details [...]
126112
//=----------------------------------------------------------------------------=
127113

128114
public extension Offsets {
129115

130-
//=------------------------------------------------------------------------=
131-
// MARK: Utilities
132-
//=------------------------------------------------------------------------=
133-
134116
@inlinable @inline(__always) func distance<T>(
135117
from start: Index, to end: Index, as type: T.Type) -> Offset<T> {
136118
distance(from: start, to: end)
@@ -143,10 +125,6 @@ public extension Offsets {
143125
return lower ..< lower + count
144126
}
145127

146-
//=------------------------------------------------------------------------=
147-
// MARK: Utilities
148-
//=------------------------------------------------------------------------=
149-
150128
@inlinable @inline(__always) func index<T>(
151129
from start: Index, move distance: Offset<T>, as type: T.Type) -> Index {
152130
index(from: start, move: distance)
@@ -165,17 +143,13 @@ public extension Offsets {
165143
}
166144

167145
//*============================================================================*
168-
// MARK: * Offsets x String, String.SubSequence
146+
// MARK: * Offsets x String, String.SubSequence [...]
169147
//*============================================================================*
170148

171149
extension String: Offsets { }
172150
extension String.SubSequence: Offsets { }
173151
public extension StringProtocol {
174152

175-
//=------------------------------------------------------------------------=
176-
// MARK: Utilities
177-
//=------------------------------------------------------------------------=
178-
179153
@inlinable @inline(__always) func distance<T>(
180154
from start: Index, to end: Index) -> Offset<T> {
181155
T.distance(from: start, to: end, in: self)
@@ -188,16 +162,12 @@ public extension StringProtocol {
188162
}
189163

190164
//*============================================================================*
191-
// MARK: * Offsets x Snapshot
165+
// MARK: * Offsets x Snapshot [...]
192166
//*============================================================================*
193167

194168
extension Snapshot: Offsets { }
195169
public extension Snapshot {
196170

197-
//=------------------------------------------------------------------------=
198-
// MARK: Utilities
199-
//=------------------------------------------------------------------------=
200-
201171
@inlinable @inline(__always) func distance<T>(
202172
from start: Index, to end: Index) -> Offset<T> {
203173
T.distance(from: start, to: end, in: self)
@@ -210,15 +180,11 @@ public extension Snapshot {
210180
}
211181

212182
//*============================================================================*
213-
// MARK: * Encoding
183+
// MARK: * Encoding [...]
214184
//*============================================================================*
215185

216186
public protocol Encoding {
217187

218-
//=------------------------------------------------------------------------=
219-
// MARK: Utilities
220-
//=------------------------------------------------------------------------=
221-
222188
@inlinable @inline(__always) static func distance(
223189
from start: String.Index, to end: String.Index,
224190
in collection: some StringProtocol) -> Offset<Self>
@@ -227,10 +193,6 @@ public protocol Encoding {
227193
from start: String.Index, move distance: Offset<Self>,
228194
in collection: some StringProtocol) -> String.Index
229195

230-
//=------------------------------------------------------------------------=
231-
// MARK: Utilities
232-
//=------------------------------------------------------------------------=
233-
234196
@inlinable @inline(__always) static func distance(
235197
from start: Snapshot.Index, to end: Snapshot.Index,
236198
in collection: Snapshot) -> Offset<Self>
@@ -241,15 +203,11 @@ public protocol Encoding {
241203
}
242204

243205
//=----------------------------------------------------------------------------=
244-
// MARK: + Details
206+
// MARK: + Details [...]
245207
//=----------------------------------------------------------------------------=
246208

247209
public extension Encoding {
248210

249-
//=------------------------------------------------------------------------=
250-
// MARK: Utilities
251-
//=------------------------------------------------------------------------=
252-
253211
@inlinable @inline(__always) static func distance(
254212
from start: Snapshot.Index, to end: Snapshot.Index,
255213
in collection: Snapshot) -> Offset<Self> {
@@ -271,16 +229,12 @@ public extension Encoding {
271229
}
272230

273231
//*============================================================================*
274-
// MARK: * Encoding x Character
232+
// MARK: * Encoding x Character [...]
275233
//*============================================================================*
276234

277235
extension Character: Encoding { }
278236
public extension Character {
279237

280-
//=------------------------------------------------------------------------=
281-
// MARK: Utilities
282-
//=------------------------------------------------------------------------=
283-
284238
@inlinable @inline(__always) static func distance(
285239
from start: String.Index, to end: String.Index,
286240
in collection: some StringProtocol) -> Offset<Self> {
@@ -293,10 +247,6 @@ public extension Character {
293247
collection.index(start, offsetBy: Int(distance))
294248
}
295249

296-
//=------------------------------------------------------------------------=
297-
// MARK: Utilities
298-
//=------------------------------------------------------------------------=
299-
300250
@inlinable @inline(__always) static func distance(
301251
from start: Snapshot.Index, to end: Snapshot.Index,
302252
in collection: Snapshot) -> Offset<Self> {
@@ -311,16 +261,12 @@ public extension Character {
311261
}
312262

313263
//*============================================================================*
314-
// MARK: * Encoding x Unicode.Scalar
264+
// MARK: * Encoding x Unicode.Scalar [...]
315265
//*============================================================================*
316266

317267
extension Unicode.Scalar: Encoding { }
318268
public extension Unicode.Scalar {
319269

320-
//=------------------------------------------------------------------------=
321-
// MARK: Utilities
322-
//=------------------------------------------------------------------------=
323-
324270
@inlinable @inline(__always) static func distance(
325271
from start: String.Index, to end: String.Index,
326272
in collection: some StringProtocol) -> Offset<Self> {
@@ -335,16 +281,12 @@ public extension Unicode.Scalar {
335281
}
336282

337283
//*============================================================================*
338-
// MARK: * Encoding x UTF16
284+
// MARK: * Encoding x UTF16 [...]
339285
//*============================================================================*
340286

341287
extension UTF16: Encoding { }
342288
public extension UTF16 {
343289

344-
//=------------------------------------------------------------------------=
345-
// MARK: Utilities
346-
//=------------------------------------------------------------------------=
347-
348290
@inlinable @inline(__always) static func distance(
349291
from start: String.Index, to end: String.Index,
350292
in collection: some StringProtocol) -> Offset<Self> {
@@ -359,16 +301,12 @@ public extension UTF16 {
359301
}
360302

361303
//*============================================================================*
362-
// MARK: * Encoding x UTF8
304+
// MARK: * Encoding x UTF8 [...]
363305
//*============================================================================*
364306

365307
extension UTF8: Encoding { }
366308
public extension UTF8 {
367309

368-
//=------------------------------------------------------------------------=
369-
// MARK: Utilities
370-
//=------------------------------------------------------------------------=
371-
372310
@inlinable @inline(__always) static func distance(
373311
from start: String.Index, to end: String.Index,
374312
in collection: some StringProtocol) -> Offset<Self> {

Sources/DiffableTextKit/Models/Selection.swift

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
///
1616
/// Equal bounds represent an upper bound.
1717
///
18-
public struct Selection<Bound: Comparable>: Equatable {
18+
public struct Selection<Bound: Comparable>: CustomStringConvertible, Equatable {
1919

2020
//=------------------------------------------------------------------------=
2121
// MARK: State
@@ -48,6 +48,14 @@ public struct Selection<Bound: Comparable>: Equatable {
4848
Self(unchecked: (collection.startIndex, collection.endIndex))
4949
}
5050

51+
//=------------------------------------------------------------------------=
52+
// MARK: Accessors
53+
//=------------------------------------------------------------------------=
54+
55+
public var description: String {
56+
String(describing: detached())
57+
}
58+
5159
//=------------------------------------------------------------------------=
5260
// MARK: Transformations
5361
//=------------------------------------------------------------------------=
@@ -66,15 +74,11 @@ public struct Selection<Bound: Comparable>: Equatable {
6674

6775
@inlinable public func map<T>(lower: (Bound) -> T, upper: (Bound) -> T) -> Selection<T> {
6876
let max = upper(self.upper); var min = max
69-
//=--------------------------------------=
70-
// Double
71-
//=--------------------------------------=
77+
7278
if self.lower != self.upper {
7379
min = Swift.min(lower(self.lower),max)
7480
}
75-
//=--------------------------------------=
76-
// Return
77-
//=--------------------------------------=
81+
7882
return Selection<T>(unchecked: (min, max))
7983
}
8084

Sources/DiffableTextKit/Models/Status.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,7 @@ public struct Status<Style: DiffableTextStyle>: Equatable {
6666
style.update(&cache); return style.interpret(value, with: &cache)
6767
}
6868

69-
@inlinable func resolve(_ proposal: Proposal, with
70-
cache: inout Cache) throws -> Commit<Style.Value> {
69+
@inlinable func resolve(_ proposal: Proposal, with cache: inout Cache) throws -> Commit<Style.Value> {
7170
style.update(&cache); return try style.resolve(proposal, with: &cache)
7271
}
7372

0 commit comments

Comments
 (0)