Skip to content

Commit 7ca5a43

Browse files
define JSONDecoder() outside of for loop in load() (#159)
this PR defines a variable, `decoder`, which represents the `JSONDecoder` class, rather than doing it in the for loop in `load()` Signed-off-by: Elijah Wright <git@elijahs.space>
1 parent 6f1f770 commit 7ca5a43

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

Sources/ContainerPersistence/EntityStore.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,12 +101,13 @@ public actor FilesystemEntityStore<T>: EntityStore where T: Codable & Identifiab
101101
private static func load(path: URL, log: Logger) throws -> Index {
102102
let directories = try FileManager.default.contentsOfDirectory(at: path, includingPropertiesForKeys: nil)
103103
var index: FilesystemEntityStore<T>.Index = Index()
104+
let decoder = JSONDecoder()
104105

105106
for entityUrl in directories {
106107
do {
107108
let metadataUrl = entityUrl.appendingPathComponent(metadataFilename)
108109
let data = try Data(contentsOf: metadataUrl)
109-
let entity = try JSONDecoder().decode(T.self, from: data)
110+
let entity = try decoder.decode(T.self, from: data)
110111
index[entity.id] = entity
111112
} catch {
112113
log.warning(

0 commit comments

Comments
 (0)