Skip to content

Commit

Permalink
Minor performance improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
Eugene Kazaev committed Oct 20, 2021
1 parent 0b619fe commit 02c4972
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 13 deletions.
2 changes: 1 addition & 1 deletion ChatLayout.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'ChatLayout'
s.version = '1.1.12'
s.version = '1.1.13'
s.summary = 'Chat UI Library. It uses custom UICollectionViewLayout to provide you full control over the presentation.'
s.swift_version = '5.2'

Expand Down
15 changes: 9 additions & 6 deletions ChatLayout/Classes/Core/Model/StateController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -633,11 +633,10 @@ final class StateController {

var startingIndex = 0
// If header is not visible
if traverseState == .notFound {
// Find if any of the items of the section is visible
if let firstMatchIndex = Array(section.items.enumerated()).binarySearch(predicate: { itemIndex, _ in
if traverseState == .notFound, !section.items.isEmpty {
func predicate(itemIndex: Int) -> ComparisonResult {
let itemPath = ItemPath(item: itemIndex, section: sectionIndex)
guard let itemFrame = self.itemFrame(for: itemPath, kind: .cell, at: state, isFinal: true) else {
guard let itemFrame = itemFrame(for: itemPath, kind: .cell, at: state, isFinal: true) else {
return .orderedDescending
}
if itemFrame.intersects(visibleRect) {
Expand All @@ -647,7 +646,11 @@ final class StateController {
return .orderedDescending
}
return .orderedAscending
}) {
}

// Find if any of the items of the section is visible
if [ComparisonResult.orderedSame, .orderedDescending].contains(predicate(itemIndex: section.items.count - 1)),
let firstMatchIndex = Array(0...section.items.count - 1).binarySearch(predicate: predicate) {
// Find first item that is visible
startingIndex = firstMatchIndex
for itemIndex in (0..<firstMatchIndex).reversed() {
Expand All @@ -662,7 +665,7 @@ final class StateController {
}
} else {
// Otherwise we can safely skip all the items in the section and go to footer.
startingIndex = section.items.count - 1
startingIndex = section.items.count
}
}

Expand Down
12 changes: 6 additions & 6 deletions Example/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
PODS:
- ChatLayout (1.1.12):
- ChatLayout/Ultimate (= 1.1.12)
- ChatLayout/Core (1.1.12)
- ChatLayout/Extras (1.1.12):
- ChatLayout (1.1.13):
- ChatLayout/Ultimate (= 1.1.13)
- ChatLayout/Core (1.1.13)
- ChatLayout/Extras (1.1.13):
- ChatLayout/Core
- ChatLayout/Ultimate (1.1.12):
- ChatLayout/Ultimate (1.1.13):
- ChatLayout/Core
- ChatLayout/Extras
- DifferenceKit (1.2.0):
Expand Down Expand Up @@ -35,7 +35,7 @@ EXTERNAL SOURCES:
:path: "../"

SPEC CHECKSUMS:
ChatLayout: 8f41f556773cc215fad67a1064ec40badcd99c83
ChatLayout: 3043e079e1b2e46239fc2f33bcbd3e679f1314cc
DifferenceKit: 5659c430bb7fe45876fa32ce5cba5d6167f0c805
FPSCounter: 884afec377de66637808c4f52ecc3b85a404732b
InputBarAccessoryView: 74d471ab1fa1736806be50328df79257e52865a9
Expand Down

0 comments on commit 02c4972

Please sign in to comment.