[ListMonitor] Use dynamicCast() to cast fetchedObjects to [T]? without checking the type.

Type checking takes a time. So there is a performance problem when casting a large number of fetched objects to an array of a certain type using the operator `as?`.
This commit is contained in:
Ruslan Skorb
2017-03-24 21:30:46 +02:00
parent 92890d1e1d
commit f055c54a66

View File

@@ -202,7 +202,7 @@ public final class ListMonitor<T: NSManagedObject>: 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 as? [T]) ?? []
return self.fetchedResultsController.dynamicCast().fetchedObjects ?? []
}
/**
@@ -371,7 +371,7 @@ public final class ListMonitor<T: NSManagedObject>: 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 as? [T] ?? []).index(of: object)
return (self.fetchedResultsController.dynamicCast().fetchedObjects ?? []).index(of: object)
}
/**