Skip to content

Commit

Permalink
Add PropertyList implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
Kyle-Ye committed Jan 1, 2024
1 parent b9ab73a commit f4a844d
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,36 +24,42 @@ struct PropertyList: CustomStringConvertible {
@inlinable
init() { elements = nil }

// TODO: See Element implementatation
@usableFromInline
var description: String {
var description = "["
var elements = elements
while let element = elements {
description.append(element.description)
elements = element.after
if elements != nil {
description.append(", ")
}
}
description.append("]")
return description
// TODO
"[]"
}

// TODO
func forEach<Key: PropertyKey>(keyType: Key.Type, _ body: (Key.Value, inout Swift.Bool) -> Void) {
guard let elements else {
return
}
elements.forEach { element, stop in
// TODO
fatalError("TODO")
}
}

// TODO:
subscript<Key: PropertyKey>(_ keyType: Key.Type) -> Key.Value {
get { fatalError("TODO") }
set { fatalError("TODO") }
get {
withExtendedLifetime(keyType) {
guard let result = find(.passUnretained(elements!), key: keyType) else {
return Key.defaultValue
}
return result.takeUnretainedValue().value
}
}
set {
if let result = find(.passUnretained(elements!), key: keyType) {
guard !compareValues(
newValue,
result.takeUnretainedValue().value,
mode: ._3
) else {
return
}
}
elements = TypedElement<Key>(value: newValue, before: nil, after: elements)
}
}

func mayNotBeEqual(to: PropertyList) -> Bool {
Expand All @@ -66,6 +72,28 @@ struct PropertyList: CustomStringConvertible {
}
return !equalResult
}

mutating func merge(_ plist: PropertyList) {
fatalError("TODO")
}

mutating private func override(with plist: PropertyList) {
if let element = elements {
elements = element.byPrepending(plist.elements)
} else {
elements = plist.elements
}
}
}

// MARK: - PropertyList Help functions

private func find<Key: PropertyKey>(
_: Unmanaged<PropertyList.Element>?,
key: Key.Type,
keyFilter: BloomFilter = BloomFilter(type: Key.self)
) -> Unmanaged<TypedElement<Key>>? {
fatalError("TODO")
}

// MARK: - PropertyList.Element
Expand Down Expand Up @@ -325,7 +353,7 @@ extension PropertyList {
}
}

// MARK: - PropertyList.Tracker Helper function
// MARK: - PropertyList.Tracker Helper functions

@_transparent
@inline(__always)
Expand Down Expand Up @@ -361,12 +389,11 @@ private func match(data: TrackerData, from: PropertyList, to: PropertyList) -> U
}

private func move(_ values: inout [ObjectIdentifier: any AnyTrackedValue], to invalidValues: inout [any AnyTrackedValue]) {
// TODO
fatalError("TODO")
}

private func compare(_ values: [ObjectIdentifier: any AnyTrackedValue], against plist: PropertyList) -> Bool {
// TODO
.random()
fatalError("TODO")
}

// MARK: - TrackerData
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//
// PropertyListTests.swift
//
//
// Created by Kyle on 2024/1/1.
//

@testable import OpenSwiftUI
import XCTest

final class PropertyListTests: XCTestCase {
func testDescription() throws {
let plist = PropertyList()
XCTAssertEqual(plist.description, "[]")
}
}

0 comments on commit f4a844d

Please sign in to comment.