Slather logo

Coverage for "ItemPath.swift" : 0.00%

(0 of 11 relevant lines covered)

ChatLayout/Classes/Core/Model/ItemPath.swift

1
//
2
// ChatLayout
3
// ItemPath.swift
4
// https://github.com/ekazaev/ChatLayout
5
//
6
// Created by Eugene Kazaev in 2020-2022.
7
// Distributed under the MIT license.
8
//
9
10
import Foundation
11
12
/// Represents the location of an item in a section.
13
///
14
/// Initializing a `ItemPath` is measurably faster than initializing an `IndexPath`.
15
/// On an iPhone X, compiled with -Os optimizations, it's about 35x faster to initialize this struct
16
/// compared to an `IndexPath`.
17
struct ItemPath: Hashable {
18
19
    let section: Int
20
21
    let item: Int
22
23
    var indexPath: IndexPath {
!
24
        return IndexPath(item: item, section: section)
!
25
    }
!
26
27
    init(item: Int, section: Int) {
!
28
        self.section = section
!
29
        self.item = item
!
30
    }
!
31
32
    init(for indexPath: IndexPath) {
!
33
        self.section = indexPath.section
!
34
        self.item = indexPath.item
!
35
    }
!
36
37
}