Skip to content

Commit 3bfc408

Browse files
authored
Cut down on calls to withMutation (#192)
1 parent aaf6057 commit 3bfc408

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

Sources/Sharing/Internal/Reference.swift

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ final class _PersistentReference<Key: SharedReaderKey>:
207207
case let .failure(error):
208208
loadError = error
209209
case let .success(newValue):
210-
loadError = nil
210+
if _loadError != nil { loadError = nil }
211211
wrappedValue = newValue ?? initialValue
212212
}
213213
}
@@ -299,7 +299,7 @@ final class _PersistentReference<Key: SharedReaderKey>:
299299
}
300300
)
301301
}
302-
loadError = nil
302+
if _loadError != nil { loadError = nil }
303303
} catch {
304304
loadError = error
305305
throw error
@@ -308,9 +308,6 @@ final class _PersistentReference<Key: SharedReaderKey>:
308308

309309
func touch() {
310310
withMutation(keyPath: \.value) {}
311-
withMutation(keyPath: \._isLoading) {}
312-
withMutation(keyPath: \._loadError) {}
313-
withMutation(keyPath: \._saveError) {}
314311
}
315312

316313
func access<Member>(
@@ -405,8 +402,8 @@ extension _PersistentReference: MutableReference, Equatable where Key: SharedKey
405402
guard let self else { return }
406403
switch result {
407404
case .success:
408-
loadError = nil
409-
saveError = nil
405+
if _loadError != nil { loadError = nil }
406+
if _saveError != nil { saveError = nil }
410407
case let .failure(error):
411408
saveError = error
412409
}
@@ -420,7 +417,7 @@ extension _PersistentReference: MutableReference, Equatable where Key: SharedKey
420417
}
421418

422419
func save() async throws {
423-
saveError = nil
420+
if _saveError != nil { saveError = nil }
424421
do {
425422
_ = try await withUnsafeThrowingContinuation { continuation in
426423
let key = key
@@ -436,7 +433,7 @@ extension _PersistentReference: MutableReference, Equatable where Key: SharedKey
436433
saveError = error
437434
throw error
438435
}
439-
loadError = nil
436+
if _loadError != nil { loadError = nil }
440437
}
441438

442439
static func == (lhs: _PersistentReference, rhs: _PersistentReference) -> Bool {

0 commit comments

Comments
 (0)