Skip to content

Commit 23df7d7

Browse files
Pull the RTLM14d "is map entry tombstoned?" check into method
The logic for this check is going to expand when we implement the tombstoning spec [1], so let's DRY it up. [1] ably/specification#350
1 parent 06e8ac2 commit 23df7d7

1 file changed

Lines changed: 8 additions & 5 deletions

File tree

Sources/AblyLiveObjects/Internal/InternalDefaultLiveMap.swift

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -147,9 +147,7 @@ internal final class InternalDefaultLiveMap: Sendable {
147147
return mutex.withLock {
148148
// RTLM10d: Returns the number of non-tombstoned entries (per RTLM14) in the internal data map
149149
mutableState.data.values.count { entry in
150-
// RTLM14a: The method returns true if ObjectsMapEntry.tombstone is true
151-
// RTLM14b: Otherwise, it returns false
152-
entry.tombstone != true
150+
!Self.isEntryTombstoned(entry)
153151
}
154152
}
155153
}
@@ -170,7 +168,7 @@ internal final class InternalDefaultLiveMap: Sendable {
170168
// RTLM11d1: Pairs with tombstoned entries (per RTLM14) are not returned
171169
var result: [(key: String, value: InternalLiveMapValue)] = []
172170

173-
for (key, entry) in mutableState.data {
171+
for (key, entry) in mutableState.data where !Self.isEntryTombstoned(entry) {
174172
// Convert entry to LiveMapValue using the same logic as get(key:)
175173
if let value = convertEntryToLiveMapValue(entry, delegate: delegate) {
176174
result.append((key: key, value: value))
@@ -682,11 +680,16 @@ internal final class InternalDefaultLiveMap: Sendable {
682680

683681
// MARK: - Helper Methods
684682

683+
/// Returns whether a map entry should be considered tombstoned, per the check described in RTLM14.
684+
private static func isEntryTombstoned(_ entry: InternalObjectsMapEntry) -> Bool {
685+
// RTLM14a, RTLM14b
686+
entry.tombstone == true
687+
}
688+
685689
/// Converts an InternalObjectsMapEntry to LiveMapValue using the same logic as get(key:)
686690
/// This is used by entries to ensure consistent value conversion
687691
private func convertEntryToLiveMapValue(_ entry: InternalObjectsMapEntry, delegate: LiveMapObjectPoolDelegate) -> InternalLiveMapValue? {
688692
// RTLM5d2a: If ObjectsMapEntry.tombstone is true, return undefined/null
689-
// This is also equivalent to the RTLM14 check
690693
if entry.tombstone == true {
691694
return nil
692695
}

0 commit comments

Comments
 (0)