Skip to content

Commit ea8d5e6

Browse files
fix code
1 parent 4f0cc1c commit ea8d5e6

File tree

1 file changed

+1
-29
lines changed

1 file changed

+1
-29
lines changed

Sources/JSONPatch/JSONPatchGenerator.swift

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -145,35 +145,7 @@ struct JSONPatchGenerator {
145145
}
146146

147147
private mutating func add(path: JSONPointer, value: JSONElement) {
148-
if let removalIndex = findPreviouslyRemoved(value: value) {
149-
guard case let .remove(removedPath, _) = operations[removalIndex] else {
150-
return
151-
}
152-
operations.remove(at: removalIndex)
153-
operations.append(.move(from: removedPath, old: value, path: path, value: value))
154-
return
155-
}
156-
if let oldPath = findUnchangedValue(value: value) {
157-
operations.append(.copy(from: oldPath, path: path, value: value))
158-
} else {
159-
operations.append(.add(path: path, value: value))
160-
}
161-
}
162-
163-
private func findUnchangedValue(value: JSONElement) -> JSONPointer? {
164-
for (pointer, old) in unchanged where value == old {
165-
return pointer
166-
}
167-
return nil
168-
}
169-
170-
private func findPreviouslyRemoved(value: JSONElement) -> Int? {
171-
return operations.firstIndex { (op) -> Bool in
172-
guard case let .remove(_, old) = op else {
173-
return false
174-
}
175-
return value == old
176-
}
148+
operations.append(.add(path: path, value: value))
177149
}
178150
}
179151

0 commit comments

Comments
 (0)