[ListMonitor] [numberOfObjects()] Calculate the number of objects in all sections by summing the number of objects stored in NSFetchedResultsSectionInfo.

There is a performance problem in Swift when calling `count` method on an array with a large number of fetched objects. It requires casting the array between Objective-C and Swift, that is pretty slow.
This commit is contained in:
Ruslan Skorb
2018-11-24 16:24:14 +02:00
parent 06c0981ded
commit 6f655951aa

View File

@@ -232,7 +232,10 @@ public final class ListMonitor<D: DynamicObject>: Hashable {
!self.isPendingRefetch || Thread.isMainThread,
"Attempted to access a \(cs_typeName(self)) outside the main thread while a refetch is in progress."
)
return self.fetchedResultsController.fetchedObjects?.count ?? 0
return self.sections().reduce(0, { (numberOfObjects, sectionInfo) -> Int in
return numberOfObjects + sectionInfo.numberOfObjects
})
}
/**