@@ -293,69 +293,71 @@ internal struct ObjectsPool {
293293 var updatesToExistingObjects : [ ObjectsPool . Entry . DeferredUpdate ] = [ ]
294294
295295 // RTO5c1: For each ObjectState member in the SyncObjectsPool list
296- for syncObjectsPoolEntry in syncObjectsPool {
297- receivedObjectIds. insert ( syncObjectsPoolEntry. state. objectId)
296+ for objectMessage in syncObjectsPool {
297+ // Every message yielded by SyncObjectsPool is guaranteed to have a non-nil `.object` with `.map` or `.counter`.
298+ let state = objectMessage. object!
299+ receivedObjectIds. insert ( state. objectId)
298300
299301 // RTO5c1a: If an object with ObjectState.objectId exists in the internal ObjectsPool
300- if let existingEntry = entries [ syncObjectsPoolEntry . state. objectId] {
301- logger. log ( " Updating existing object with ID: \( syncObjectsPoolEntry . state. objectId) " , level: . debug)
302+ if let existingEntry = entries [ state. objectId] {
303+ logger. log ( " Updating existing object with ID: \( state. objectId) " , level: . debug)
302304
303305 // RTO5c1a1: Override the internal data for the object as per RTLC6, RTLM6
304306 let deferredUpdate = existingEntry. nosync_replaceData (
305- using: syncObjectsPoolEntry . state,
306- objectMessageSerialTimestamp: syncObjectsPoolEntry . objectMessageSerialTimestamp ,
307+ using: state,
308+ objectMessageSerialTimestamp: objectMessage . serialTimestamp ,
307309 objectsPool: & self ,
308310 userCallbackQueue: userCallbackQueue,
309311 )
310312 // RTO5c1a2: Store this update to emit at end
311313 updatesToExistingObjects. append ( deferredUpdate)
312314 } else {
313315 // RTO5c1b: If an object with ObjectState.objectId does not exist in the internal ObjectsPool
314- logger. log ( " Creating new object with ID: \( syncObjectsPoolEntry . state. objectId) " , level: . debug)
316+ logger. log ( " Creating new object with ID: \( state. objectId) " , level: . debug)
315317
316318 // RTO5c1b1: Create a new LiveObject using the data from ObjectState and add it to the internal ObjectsPool:
317319 let newEntry : Entry
318320
319- if syncObjectsPoolEntry . state. counter != nil {
321+ if state. counter != nil {
320322 // RTO5c1b1a: If ObjectState.counter is present, create a zero-value LiveCounter,
321323 // set its private objectId equal to ObjectState.objectId and override its internal data per RTLC6
322324 let counter = InternalDefaultLiveCounter . createZeroValued (
323- objectID: syncObjectsPoolEntry . state. objectId,
325+ objectID: state. objectId,
324326 logger: logger,
325327 internalQueue: internalQueue,
326328 userCallbackQueue: userCallbackQueue,
327329 clock: clock,
328330 )
329331 _ = counter. nosync_replaceData (
330- using: syncObjectsPoolEntry . state,
331- objectMessageSerialTimestamp: syncObjectsPoolEntry . objectMessageSerialTimestamp ,
332+ using: state,
333+ objectMessageSerialTimestamp: objectMessage . serialTimestamp ,
332334 )
333335 newEntry = . counter( counter)
334- } else if let objectsMap = syncObjectsPoolEntry . state. map {
336+ } else if let objectsMap = state. map {
335337 // RTO5c1b1b: If ObjectState.map is present, create a zero-value LiveMap,
336338 // set its private objectId equal to ObjectState.objectId, set its private semantics
337339 // equal to ObjectState.map.semantics and override its internal data per RTLM6
338340 let map = InternalDefaultLiveMap . createZeroValued (
339- objectID: syncObjectsPoolEntry . state. objectId,
341+ objectID: state. objectId,
340342 semantics: objectsMap. semantics,
341343 logger: logger,
342344 internalQueue: internalQueue,
343345 userCallbackQueue: userCallbackQueue,
344346 clock: clock,
345347 )
346348 _ = map. nosync_replaceData (
347- using: syncObjectsPoolEntry . state,
348- objectMessageSerialTimestamp: syncObjectsPoolEntry . objectMessageSerialTimestamp ,
349+ using: state,
350+ objectMessageSerialTimestamp: objectMessage . serialTimestamp ,
349351 objectsPool: & self ,
350352 )
351353 newEntry = . map( map)
352354 } else {
353- // See SyncObjectsPool.Entry.state documentation .
354- preconditionFailure ( " SyncObjectsPool entry for objectId \( syncObjectsPoolEntry . state. objectId) has neither counter nor map " )
355+ // SyncObjectsPool guarantees every yielded message has `.map` or `.counter` .
356+ preconditionFailure ( " SyncObjectsPool entry for objectId \( state. objectId) has neither counter nor map " )
355357 }
356358
357359 // Note that we will never replace the root object here, and thus never break the RTO3b invariant that the root object is always a map. This is because the pool always contains a root object and thus we always go through the RTO5c1a branch of the `if` above.
358- entries [ syncObjectsPoolEntry . state. objectId] = newEntry
360+ entries [ state. objectId] = newEntry
359361 }
360362 }
361363
0 commit comments