Skip to content

Commit 5ba64a2

Browse files
Pull the RTLM14d "is map entry tombstoned?" check into method
The logic for this check is going to expand, so let's DRY it up.
1 parent 9e040c4 commit 5ba64a2

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

Sources/AblyLiveObjects/Internal/InternalDefaultLiveMap.swift

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -150,9 +150,7 @@ internal final class InternalDefaultLiveMap: Sendable {
150150
return mutex.withLock {
151151
// RTLM10d: Returns the number of non-tombstoned entries (per RTLM14) in the internal data map
152152
mutableState.data.values.count { entry in
153-
// RTLM14a: The method returns true if ObjectsMapEntry.tombstone is true
154-
// RTLM14b: Otherwise, it returns false
155-
entry.tombstone != true
153+
!Self.isEntryTombstoned(entry)
156154
}
157155
}
158156
}
@@ -173,7 +171,7 @@ internal final class InternalDefaultLiveMap: Sendable {
173171
// RTLM11d1: Pairs with tombstoned entries (per RTLM14) are not returned
174172
var result: [(key: String, value: InternalLiveMapValue)] = []
175173

176-
for (key, entry) in mutableState.data {
174+
for (key, entry) in mutableState.data where !Self.isEntryTombstoned(entry) {
177175
// Convert entry to LiveMapValue using the same logic as get(key:)
178176
if let value = convertEntryToLiveMapValue(entry, delegate: delegate) {
179177
result.append((key: key, value: value))
@@ -778,11 +776,16 @@ internal final class InternalDefaultLiveMap: Sendable {
778776

779777
// MARK: - Helper Methods
780778

779+
/// Returns whether a map entry should be considered tombstoned, per the check described in RTLM14.
780+
private static func isEntryTombstoned(_ entry: InternalObjectsMapEntry) -> Bool {
781+
// RTLM14a, RTLM14b
782+
entry.tombstone
783+
}
784+
781785
/// Converts an InternalObjectsMapEntry to LiveMapValue using the same logic as get(key:)
782786
/// This is used by entries to ensure consistent value conversion
783787
private func convertEntryToLiveMapValue(_ entry: InternalObjectsMapEntry, delegate: LiveMapObjectPoolDelegate) -> InternalLiveMapValue? {
784788
// RTLM5d2a: If ObjectsMapEntry.tombstone is true, return undefined/null
785-
// This is also equivalent to the RTLM14 check
786789
if entry.tombstone == true {
787790
return nil
788791
}

0 commit comments

Comments
 (0)