Skip to content

Commit

Permalink
DisplayList.Value.init(decodedValue:) updates lastValue (#184)
Browse files Browse the repository at this point in the history
* DisplayList.Value.init(decodedValue:) updates lastValue

* Update test case for DisplayList.Version

---------

Co-authored-by: Kyle <kyle201817146@gmail.com>
  • Loading branch information
pookjw and Kyle-Ye authored Jan 25, 2025
1 parent 0e239ac commit 74c4d2f
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
10 changes: 7 additions & 3 deletions Sources/OpenSwiftUICore/Render/DisplayList/DisplayList.swift
Original file line number Diff line number Diff line change
Expand Up @@ -214,12 +214,16 @@ extension DisplayList {
// }

package struct Version: Comparable, Hashable {
private static var lastValue: Int = .zero

package private(set) var value: Int

package init() { value = .zero }
package init(decodedValue value: Int) { self.value = value }

private static var lastValue: Int = .zero
package init(decodedValue value: Int) {
Version.lastValue = max(Version.lastValue, value)
self.value = value
}

package init(forUpdate: Void) {
Version.lastValue &+= 1
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//
// DisplayListTests.swift
// OpenSwiftUICoreTests

import OpenSwiftUICore
import Testing

struct DisplayListTests {
@Test
@MainActor
func version() {
typealias Version = DisplayList.Version
let v0 = Version()
let v1 = Version(decodedValue: 999)
let v2 = Version(forUpdate: ())
#expect(v0.value == 0)
#expect(v1.value == 999)
#expect(v2.value == 1000)
#expect(v1 < v2)

var combineVersion = v0
#expect(combineVersion.value == 0)
combineVersion.combine(with: v1)
#expect(combineVersion.value == 999)
}
}

0 comments on commit 74c4d2f

Please sign in to comment.