|
3 | 3 | // OpenSwiftUICore
|
4 | 4 | //
|
5 | 5 | // Audited for iOS 18.0
|
6 |
| -// Status: Blocked by merge |
| 6 | +// Status: Complete |
7 | 7 | // ID: 2B32D570B0B3D2A55DA9D4BFC1584D20 (SwiftUI)
|
8 | 8 | // ID: D64CE6C88E7413721C59A34C0C940F2C (SwiftUICore)
|
9 | 9 |
|
@@ -201,15 +201,70 @@ package struct PropertyList: CustomStringConvertible {
|
201 | 201 | }
|
202 | 202 | }
|
203 | 203 |
|
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 | + } |
207 | 215 | 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 | + } |
208 | 254 | guard copyCount != 0 else {
|
209 | 255 | return
|
210 | 256 | }
|
211 | 257 | 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 | + } |
213 | 268 | }
|
214 | 269 | }
|
215 | 270 |
|
|
0 commit comments