Skip to content

Commit 74c4d2f

Browse files
pookjwKyle-Ye
andauthored
DisplayList.Value.init(decodedValue:) updates lastValue (#184)
* DisplayList.Value.init(decodedValue:) updates lastValue * Update test case for DisplayList.Version --------- Co-authored-by: Kyle <[email protected]>
1 parent 0e239ac commit 74c4d2f

File tree

2 files changed

+33
-3
lines changed

2 files changed

+33
-3
lines changed

Sources/OpenSwiftUICore/Render/DisplayList/DisplayList.swift

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -214,12 +214,16 @@ extension DisplayList {
214214
// }
215215

216216
package struct Version: Comparable, Hashable {
217+
private static var lastValue: Int = .zero
218+
217219
package private(set) var value: Int
218-
220+
219221
package init() { value = .zero }
220-
package init(decodedValue value: Int) { self.value = value }
221222

222-
private static var lastValue: Int = .zero
223+
package init(decodedValue value: Int) {
224+
Version.lastValue = max(Version.lastValue, value)
225+
self.value = value
226+
}
223227

224228
package init(forUpdate: Void) {
225229
Version.lastValue &+= 1
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
//
2+
// DisplayListTests.swift
3+
// OpenSwiftUICoreTests
4+
5+
import OpenSwiftUICore
6+
import Testing
7+
8+
struct DisplayListTests {
9+
@Test
10+
@MainActor
11+
func version() {
12+
typealias Version = DisplayList.Version
13+
let v0 = Version()
14+
let v1 = Version(decodedValue: 999)
15+
let v2 = Version(forUpdate: ())
16+
#expect(v0.value == 0)
17+
#expect(v1.value == 999)
18+
#expect(v2.value == 1000)
19+
#expect(v1 < v2)
20+
21+
var combineVersion = v0
22+
#expect(combineVersion.value == 0)
23+
combineVersion.combine(with: v1)
24+
#expect(combineVersion.value == 999)
25+
}
26+
}

0 commit comments

Comments
 (0)