mirror of
https://github.com/SideStore/SideStore.git
synced 2026-02-14 09:13:25 +01:00
[DataHolder]: Fixes for out-of-bounds condition and revert back to if-else instead of guard-else for better representation of logic
This commit is contained in:
@@ -77,7 +77,13 @@ public class PaginationDataHolder {
|
||||
let count = UInt(items.count)
|
||||
|
||||
if(count == 0) { return items }
|
||||
|
||||
|
||||
// since we operate on any input items list at any time,
|
||||
// we set currentPageIndex as last availablePage if out of bounds
|
||||
let availablePages = UInt(ceil(Double(count) / Double(itemsPerPage)))
|
||||
|
||||
self.currentPageindex = min(availablePages-1, currentPageindex)
|
||||
|
||||
let startIndex = currentPageindex * itemsPerPage
|
||||
let estimatedEndIndex = startIndex + (itemsPerPage-1)
|
||||
let endIndex: UInt = min(count-1, estimatedEndIndex)
|
||||
|
||||
Reference in New Issue
Block a user