Skip to content

Commit d7dd5b5

Browse files
committed
Fixed: Snapshot/distance(from:to:) is now O(1).
1 parent 2be0c99 commit d7dd5b5

File tree

3 files changed

+6
-20
lines changed

3 files changed

+6
-20
lines changed

Sources/DiffableTextKit/Models/Offset.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ public extension Character {
300300
@inlinable @inline(__always) static func distance(
301301
from start: Snapshot.Index, to end: Snapshot.Index,
302302
in collection: Snapshot) -> Offset<Self> {
303-
Offset(end.attribute - start.attribute)
303+
Offset(collection.distance(from: start, to: end))
304304
}
305305

306306
@inlinable @inline(__always) static func index(

Sources/DiffableTextKit/Models/Snapshot.swift

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ extension Snapshot {
187187
}
188188

189189
//=------------------------------------------------------------------------=
190-
// MARK: After, Before, Distance
190+
// MARK: After, Before
191191
//=------------------------------------------------------------------------=
192192

193193
@inlinable public func index(after position: Index) -> Index {
@@ -207,25 +207,11 @@ extension Snapshot {
207207
}
208208

209209
//=------------------------------------------------------------------------=
210-
// MARK: Count
210+
// MARK: Distance, Count
211211
//=------------------------------------------------------------------------=
212212

213-
/// - Complexity: O(1).
214-
@inlinable @inline(__always)
215-
public var isEmpty: Bool {
216-
_attributes.isEmpty
217-
}
218-
219-
/// - Complexity: O(1).
220-
@inlinable @inline(__always)
221-
public var count: Int {
222-
_attributes.count
223-
}
224-
225-
/// - Complexity: O(1).
226-
@inlinable @inline(__always)
227-
public var underestimatedCount: Int {
228-
_attributes.underestimatedCount
213+
@inlinable public func distance(from start: Index, to end: Index) -> Int {
214+
_attributes.distance(from: start.attribute,to: end.attribute)
229215
}
230216
}
231217

Sources/DiffableTextKitXPattern/Style.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ extension PatternTextStyle {
232232
if qIndex == pattern.endIndex {
233233
none(&result, pattern[pIndex ..< pIndex])
234234
//=----------------------------------=
235-
// Placeholder >= 1
235+
// Placeholders >= 1
236236
//=----------------------------------=
237237
} else {
238238
none(&result, pattern[pIndex ..< qIndex])

0 commit comments

Comments
 (0)