Simplify DatabaseRegion.iisModified(by:)

There is no "fast path" any longer. Performance impact should be minimal since most observers call `stopObservingDatabaseChangesUntilNextTransaction` on first impactful change anyway.
This commit is contained in:
Gwendal Roué committed 2019-09-26 06:55:54 +02:00
1 parent 1b753802dd
commit 0d961ce48e
1 file changed
+7 -30
+7 -30
View File
@@ -184,37 +184,14 @@ extension DatabaseRegion {
return true
}
if tableRegions.count == 1 {
// Fast path when the region contains a single table.
//
// We can apply the precondition: due to the filtering of events
// performed in observes(eventsOfKind:), the event argument is
// guaranteed to be about the fetched table. We thus only have to
// check for rowIds.
let (tableName, tableRegion) = tableRegions[tableRegions.startIndex]
if event.tableName == tableName {
return tableRegion.contains(rowID: event.rowID)
} else {
// Shouldn't happen if the precondition is met.
// But FTS4 (and maybe other virtual tables) perform
// unadvertised changes. So let's assume the region is modified,
// just is case.
// See https://github.com/groue/GRDB.swift/issues/620
return true
}
} else {
// Slow path when several tables are observed.
guard let tableRegion = tableRegions[event.tableName] else {
// Shouldn't happen if the precondition is met.
// But FTS4 (and maybe other virtual tables) perform
// unadvertised changes. So let's assume the region is modified,
// just is case.
// See https://github.com/groue/GRDB.swift/issues/620
return true
}
return tableRegion.contains(rowID: event.rowID)
guard let tableRegion = tableRegions[event.tableName] else {
// FTS4 (and maybe other virtual tables) perform unadvertised
// changes. So let's assume the precondition is fulfilled, and
// the region is modified, just in case.
// See https://github.com/groue/GRDB.swift/issues/620
return true
}
return tableRegion.contains(rowID: event.rowID)
}
}