Skip to content

Commit 2f60de6

Browse files
lhowardampcode-com
andcommitted
fix StaticProperty.subject: use stored property instead of computed to avoid allocating a new subject on every access
Amp-Thread-ID: https://ampcode.com/threads/T-019d1236-110d-717d-b5cc-faefb53720a3 Co-authored-by: Amp <amp@ampcode.com>
1 parent 2f5da9a commit 2f60de6

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

Sources/SwiftOCA/OCC/ControlClasses/Root.swift

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,13 @@ public extension OcaRoot {
313313
var setMethodID: OcaMethodID? { nil }
314314
var propertyIDs: [OcaPropertyID]
315315
var value: T
316+
let subject: AsyncCurrentValueSubject<PropertyValue>
317+
318+
init(propertyIDs: [OcaPropertyID], value: T) {
319+
self.propertyIDs = propertyIDs
320+
self.value = value
321+
subject = AsyncCurrentValueSubject(.success(value))
322+
}
316323

317324
func refresh(_ object: SwiftOCA.OcaRoot) async {}
318325
func subscribe(_ object: OcaRoot) async {}
@@ -325,10 +332,6 @@ public extension OcaRoot {
325332
OcaProperty<Value>.PropertyValue.success(value)
326333
}
327334

328-
var subject: AsyncCurrentValueSubject<PropertyValue> {
329-
AsyncCurrentValueSubject(currentValue)
330-
}
331-
332335
@_spi(SwiftOCAPrivate) @discardableResult
333336
public func _getValue(
334337
_ object: OcaRoot,

0 commit comments

Comments
 (0)