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