Skip to content

Commit 7d70450

Browse files
committed
Cleanup.
1 parent 627b949 commit 7d70450

File tree

2 files changed

+17
-43
lines changed

2 files changed

+17
-43
lines changed

Sources/DiffableTextKit/Models/Context.swift

Lines changed: 12 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
// MARK: * Context
1212
//*============================================================================*
1313

14-
/// State of a diffable text view.
14+
/// A diffable text view state model.
1515
public struct Context<Style: DiffableTextStyle> {
1616

1717
public typealias Cache = Style.Cache
@@ -75,21 +75,17 @@ public struct Context<Style: DiffableTextStyle> {
7575
}
7676

7777
//*========================================================================*
78-
// MARK: * Transaction
78+
// MARK: * Transaction [...]
7979
//*========================================================================*
8080

8181
@usableFromInline struct Transaction {
8282

8383
//=--------------------------------------------------------------------=
84-
// MARK: State
85-
//=--------------------------------------------------------------------=
8684

8785
@usableFromInline private(set) var status: Status
8886
@usableFromInline private(set) var base: Snapshot?
8987
@usableFromInline private(set) var backup: String?
9088

91-
//=--------------------------------------------------------------------=
92-
// MARK: Initializers
9389
//=--------------------------------------------------------------------=
9490

9591
@inlinable init(_ status: Status, with cache: inout Cache,
@@ -122,39 +118,21 @@ extension Context {
122118
// MARK: Storage
123119
//=------------------------------------------------------------------------=
124120

125-
@inlinable @inline(__always)
126-
var status: Status {
127-
storage.status
128-
}
121+
@inlinable @inline(__always) var status: Status { storage.status }
129122

130-
@inlinable @inline(__always)
131-
var layout: Layout? {
132-
storage.layout
133-
}
123+
@inlinable @inline(__always) var layout: Layout? { storage.layout }
134124

135-
@inlinable @inline(__always)
136-
var backup: String? {
137-
storage.backup
138-
}
125+
@inlinable @inline(__always) var backup: String? { storage.backup }
139126

140127
//=------------------------------------------------------------------------=
141128
// MARK: Status
142129
//=------------------------------------------------------------------------=
143130

144-
@inlinable @inline(__always)
145-
public var style: Style {
146-
status.style
147-
}
131+
@inlinable @inline(__always) public var style: Style { status.style }
148132

149-
@inlinable @inline(__always)
150-
public var value: Value {
151-
status.value
152-
}
133+
@inlinable @inline(__always) public var value: Value { status.value }
153134

154-
@inlinable @inline(__always)
155-
public var focus: Focus {
156-
status.focus
157-
}
135+
@inlinable @inline(__always) public var focus: Focus { status.focus }
158136

159137
//=------------------------------------------------------------------------=
160138
// MARK: Layout
@@ -239,9 +217,8 @@ extension Context {
239217
//=------------------------------------------------------------------------=
240218

241219
/// Call this on changes to text.
242-
@inlinable public mutating func merge<T>(
243-
_ characters: String, in range: Range<Offset<T>>,
244-
with cache: inout Cache) throws -> Update {
220+
@inlinable public mutating func merge<T>(_ characters: String,
221+
in range: Range<Offset<T>>, with cache: inout Cache) throws -> Update {
245222
//=--------------------------------------=
246223
// Layout
247224
//=--------------------------------------=
@@ -286,15 +263,12 @@ extension Context {
286263
//=--------------------------------------=
287264
// Values
288265
//=--------------------------------------=
289-
let selection = Selection(
290-
layout!.snapshot.indices(at: selection))
266+
let selection = Selection(layout!.snapshot.indices(at: selection))
291267
//=--------------------------------------=
292268
// Update
293269
//=--------------------------------------=
294270
self.unique()
295-
self.storage.layout!.merge(
296-
selection: selection,
297-
momentums: momentums)
271+
self.storage.layout!.merge(selection: selection,momentums: momentums)
298272
//=--------------------------------------=
299273
// Return
300274
//=--------------------------------------=

Sources/DiffableTextKit/Styles/Prefix.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,17 +52,17 @@ public struct PrefixTextStyle<Base: DiffableTextStyle>: WrapperTextStyle {
5252
// MARK: Helpers
5353
//=------------------------------------------------------------------------=
5454

55-
@inlinable func label(_ text: inout String) {
56-
if !prefix.isEmpty { text = prefix + text }
55+
@inlinable func label(_ text: inout String) {
56+
guard !prefix.isEmpty else { return }
57+
text = prefix + text
5758
}
5859

5960
@inlinable func label(_ commit: inout Commit<Value>) {
6061
guard !prefix.isEmpty else { return }
6162
let base = commit.snapshot
62-
6363
commit.snapshot = Snapshot(prefix, as: .phantom)
64-
let size = commit.snapshot.count /*-----------*/
65-
commit.snapshot.append(contentsOf: /*---*/ base)
64+
let size = commit.snapshot.count
65+
commit.snapshot.append(contentsOf: base)
6666

6767
guard let selection = base.selection else { return }
6868
let offsets = selection.map({ size + $0.attribute })

0 commit comments

Comments
 (0)