Skip to content

Commit 02c4972

Browse files
author
Eugene Kazaev
committed
Minor performance improvements
1 parent 0b619fe commit 02c4972

File tree

3 files changed

+16
-13
lines changed

3 files changed

+16
-13
lines changed

ChatLayout.podspec

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = 'ChatLayout'
3-
s.version = '1.1.12'
3+
s.version = '1.1.13'
44
s.summary = 'Chat UI Library. It uses custom UICollectionViewLayout to provide you full control over the presentation.'
55
s.swift_version = '5.2'
66

ChatLayout/Classes/Core/Model/StateController.swift

+9-6
Original file line numberDiff line numberDiff line change
@@ -633,11 +633,10 @@ final class StateController {
633633

634634
var startingIndex = 0
635635
// If header is not visible
636-
if traverseState == .notFound {
637-
// Find if any of the items of the section is visible
638-
if let firstMatchIndex = Array(section.items.enumerated()).binarySearch(predicate: { itemIndex, _ in
636+
if traverseState == .notFound, !section.items.isEmpty {
637+
func predicate(itemIndex: Int) -> ComparisonResult {
639638
let itemPath = ItemPath(item: itemIndex, section: sectionIndex)
640-
guard let itemFrame = self.itemFrame(for: itemPath, kind: .cell, at: state, isFinal: true) else {
639+
guard let itemFrame = itemFrame(for: itemPath, kind: .cell, at: state, isFinal: true) else {
641640
return .orderedDescending
642641
}
643642
if itemFrame.intersects(visibleRect) {
@@ -647,7 +646,11 @@ final class StateController {
647646
return .orderedDescending
648647
}
649648
return .orderedAscending
650-
}) {
649+
}
650+
651+
// Find if any of the items of the section is visible
652+
if [ComparisonResult.orderedSame, .orderedDescending].contains(predicate(itemIndex: section.items.count - 1)),
653+
let firstMatchIndex = Array(0...section.items.count - 1).binarySearch(predicate: predicate) {
651654
// Find first item that is visible
652655
startingIndex = firstMatchIndex
653656
for itemIndex in (0..<firstMatchIndex).reversed() {
@@ -662,7 +665,7 @@ final class StateController {
662665
}
663666
} else {
664667
// Otherwise we can safely skip all the items in the section and go to footer.
665-
startingIndex = section.items.count - 1
668+
startingIndex = section.items.count
666669
}
667670
}
668671

Example/Podfile.lock

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
PODS:
2-
- ChatLayout (1.1.12):
3-
- ChatLayout/Ultimate (= 1.1.12)
4-
- ChatLayout/Core (1.1.12)
5-
- ChatLayout/Extras (1.1.12):
2+
- ChatLayout (1.1.13):
3+
- ChatLayout/Ultimate (= 1.1.13)
4+
- ChatLayout/Core (1.1.13)
5+
- ChatLayout/Extras (1.1.13):
66
- ChatLayout/Core
7-
- ChatLayout/Ultimate (1.1.12):
7+
- ChatLayout/Ultimate (1.1.13):
88
- ChatLayout/Core
99
- ChatLayout/Extras
1010
- DifferenceKit (1.2.0):
@@ -35,7 +35,7 @@ EXTERNAL SOURCES:
3535
:path: "../"
3636

3737
SPEC CHECKSUMS:
38-
ChatLayout: 8f41f556773cc215fad67a1064ec40badcd99c83
38+
ChatLayout: 3043e079e1b2e46239fc2f33bcbd3e679f1314cc
3939
DifferenceKit: 5659c430bb7fe45876fa32ce5cba5d6167f0c805
4040
FPSCounter: 884afec377de66637808c4f52ecc3b85a404732b
4141
InputBarAccessoryView: 74d471ab1fa1736806be50328df79257e52865a9

0 commit comments

Comments
 (0)