Skip to content

Commit c2a1ec1

Browse files
committed
Complete PropertyList implementation
1 parent 49fb949 commit c2a1ec1

File tree

1 file changed

+60
-5
lines changed

1 file changed

+60
-5
lines changed

Sources/OpenSwiftUICore/Data/PropertyList.swift

Lines changed: 60 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// OpenSwiftUICore
44
//
55
// Audited for iOS 18.0
6-
// Status: Blocked by merge
6+
// Status: Complete
77
// ID: 2B32D570B0B3D2A55DA9D4BFC1584D20 (SwiftUI)
88
// ID: D64CE6C88E7413721C59A34C0C940F2C (SwiftUICore)
99

@@ -201,15 +201,70 @@ package struct PropertyList: CustomStringConvertible {
201201
}
202202
}
203203

204-
package mutating func merge(_ plist: PropertyList) {
205-
// preconditionFailure("TODO")
206-
204+
package mutating func merge(_ other: PropertyList) {
205+
guard let selfElements = self.elements else {
206+
elements = other.elements
207+
return
208+
}
209+
guard let otherElements = other.elements else {
210+
return
211+
}
212+
guard elements !== otherElements else {
213+
return
214+
}
207215
var copyCount = 0
216+
var currentSelfElement = selfElements
217+
var currentOptionalSelfElement: Element? = elements
218+
var currentOtherElement = otherElements
219+
var currentOptinoalOtherElement: Element? = otherElements
220+
repeat {
221+
if currentOtherElement.length >= currentSelfElement.length {
222+
copyCount += 1
223+
currentOptinoalOtherElement = currentOtherElement.after
224+
if let after = currentOtherElement.after {
225+
currentOtherElement = after
226+
continue
227+
} else {
228+
break
229+
}
230+
} else {
231+
currentOptionalSelfElement = currentSelfElement.after
232+
if let after = currentSelfElement.after {
233+
currentSelfElement = after
234+
continue
235+
} else {
236+
break
237+
}
238+
}
239+
} while currentSelfElement !== currentOtherElement
240+
guard let currentOptionalSelfElement,
241+
let currentOptinoalOtherElement,
242+
currentOptionalSelfElement === currentOptinoalOtherElement
243+
else {
244+
override(with: other)
245+
return
246+
}
247+
guard currentOptionalSelfElement !== otherElements else {
248+
return
249+
}
250+
guard currentOptionalSelfElement !== selfElements else {
251+
elements = otherElements
252+
return
253+
}
208254
guard copyCount != 0 else {
209255
return
210256
}
211257
withUnsafeTuple(of: TupleType(Element.self), count: copyCount) { tuple in
212-
// TODO
258+
let pointer = tuple.address(as: Element.self)
259+
var current: Element! = otherElements
260+
for index in 0 ..< copyCount {
261+
pointer[index] = current
262+
current = current.after
263+
}
264+
for index in 0 ..< copyCount {
265+
let element = pointer[copyCount - index - 1]
266+
elements = element.copy(before: element.before, after: elements)
267+
}
213268
}
214269
}
215270

0 commit comments

Comments
 (0)