From f055c54a6684807f8843bbff936226f17a020381 Mon Sep 17 00:00:00 2001 From: Ruslan Skorb Date: Fri, 24 Mar 2017 21:30:46 +0200 Subject: [PATCH] [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?`. --- Sources/Observing/ListMonitor.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sources/Observing/ListMonitor.swift b/Sources/Observing/ListMonitor.swift index ad96481..342f211 100644 --- a/Sources/Observing/ListMonitor.swift +++ b/Sources/Observing/ListMonitor.swift @@ -202,7 +202,7 @@ public final class ListMonitor: 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: 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) } /**