Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use @inlinable and remove redundant helper function #105

Merged
merged 7 commits into from
Jan 11, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions SectionKit.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
5A0B776C26B1828400B054D4 /* SingleSectionCollectionViewAdapterTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5A0B776B26B1828400B054D4 /* SingleSectionCollectionViewAdapterTests.swift */; };
5A0B776E26B19E8C00B054D4 /* MockSingleSectionCollectionViewAdapterDataSource.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5A0B776D26B19E8C00B054D4 /* MockSingleSectionCollectionViewAdapterDataSource.swift */; };
5A0B777026B19EB300B054D4 /* MockListCollectionViewAdapterDataSource.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5A0B776F26B19EB300B054D4 /* MockListCollectionViewAdapterDataSource.swift */; };
5A0B777226B1A13B00B054D4 /* SequenceGroupTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5A0B777126B1A13B00B054D4 /* SequenceGroupTests.swift */; };
5A0B777426B1A51C00B054D4 /* IndexPathIsValidTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5A0B777326B1A51C00B054D4 /* IndexPathIsValidTests.swift */; };
5A0B777626B1A5F400B054D4 /* ArraySectionIndexPathTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5A0B777526B1A5F400B054D4 /* ArraySectionIndexPathTests.swift */; };
5A0B777826B1A6AD00B054D4 /* CollectionExtensionsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5A0B777726B1A6AD00B054D4 /* CollectionExtensionsTests.swift */; };
Expand Down Expand Up @@ -88,7 +87,6 @@
5AE175DF2667DA3F00D4DCE1 /* CollectionDifference+Changes.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5AE175A32667DA3E00D4DCE1 /* CollectionDifference+Changes.swift */; };
5AE175E02667DA3F00D4DCE1 /* Move.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5AE175A42667DA3E00D4DCE1 /* Move.swift */; };
5AE175E12667DA3F00D4DCE1 /* IndexPath+IsValid.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5AE175A52667DA3E00D4DCE1 /* IndexPath+IsValid.swift */; };
5AE175E22667DA3F00D4DCE1 /* Sequence+Group.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5AE175A62667DA3E00D4DCE1 /* Sequence+Group.swift */; };
5AE175E32667DA3F00D4DCE1 /* UICollectionView+Apply.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5AE175A72667DA3E00D4DCE1 /* UICollectionView+Apply.swift */; };
5AE175E42667DA3F00D4DCE1 /* Collection+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5AE175A82667DA3E00D4DCE1 /* Collection+Extensions.swift */; };
5AE175E52667DA3F00D4DCE1 /* SectionDropDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5AE175AA2667DA3E00D4DCE1 /* SectionDropDelegate.swift */; };
Expand Down Expand Up @@ -171,7 +169,6 @@
5A0B776B26B1828400B054D4 /* SingleSectionCollectionViewAdapterTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SingleSectionCollectionViewAdapterTests.swift; sourceTree = "<group>"; };
5A0B776D26B19E8C00B054D4 /* MockSingleSectionCollectionViewAdapterDataSource.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MockSingleSectionCollectionViewAdapterDataSource.swift; sourceTree = "<group>"; };
5A0B776F26B19EB300B054D4 /* MockListCollectionViewAdapterDataSource.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MockListCollectionViewAdapterDataSource.swift; sourceTree = "<group>"; };
5A0B777126B1A13B00B054D4 /* SequenceGroupTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SequenceGroupTests.swift; sourceTree = "<group>"; };
5A0B777326B1A51C00B054D4 /* IndexPathIsValidTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IndexPathIsValidTests.swift; sourceTree = "<group>"; };
5A0B777526B1A5F400B054D4 /* ArraySectionIndexPathTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ArraySectionIndexPathTests.swift; sourceTree = "<group>"; };
5A0B777726B1A6AD00B054D4 /* CollectionExtensionsTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CollectionExtensionsTests.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -235,7 +232,6 @@
5AE175A32667DA3E00D4DCE1 /* CollectionDifference+Changes.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "CollectionDifference+Changes.swift"; sourceTree = "<group>"; };
5AE175A42667DA3E00D4DCE1 /* Move.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Move.swift; sourceTree = "<group>"; };
5AE175A52667DA3E00D4DCE1 /* IndexPath+IsValid.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "IndexPath+IsValid.swift"; sourceTree = "<group>"; };
5AE175A62667DA3E00D4DCE1 /* Sequence+Group.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Sequence+Group.swift"; sourceTree = "<group>"; };
5AE175A72667DA3E00D4DCE1 /* UICollectionView+Apply.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UICollectionView+Apply.swift"; sourceTree = "<group>"; };
5AE175A82667DA3E00D4DCE1 /* Collection+Extensions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Collection+Extensions.swift"; sourceTree = "<group>"; };
5AE175AA2667DA3E00D4DCE1 /* SectionDropDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SectionDropDelegate.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -535,7 +531,6 @@
isa = PBXGroup;
children = (
5AE175A22667DA3E00D4DCE1 /* Sequence+Unique.swift */,
5AE175A62667DA3E00D4DCE1 /* Sequence+Group.swift */,
5AE175A52667DA3E00D4DCE1 /* IndexPath+IsValid.swift */,
5AE175A42667DA3E00D4DCE1 /* Move.swift */,
5AE175A32667DA3E00D4DCE1 /* CollectionDifference+Changes.swift */,
Expand Down Expand Up @@ -677,7 +672,6 @@
isa = PBXGroup;
children = (
5AE176182667DA7000D4DCE1 /* SequenceUniqueTests.swift */,
5A0B777126B1A13B00B054D4 /* SequenceGroupTests.swift */,
5A0B777326B1A51C00B054D4 /* IndexPathIsValidTests.swift */,
5A0B777526B1A5F400B054D4 /* ArraySectionIndexPathTests.swift */,
5A0B777726B1A6AD00B054D4 /* CollectionExtensionsTests.swift */,
Expand Down Expand Up @@ -850,7 +844,6 @@
5AE175F72667DA3F00D4DCE1 /* CollectionViewContext.swift in Sources */,
5AE176082667DA3F00D4DCE1 /* SingleSectionCollectionViewAdapter+UICollectionViewDelegateFlowLayout.swift in Sources */,
5AE175E82667DA3F00D4DCE1 /* CollectionViewContext+CollectionViewSectionUpdate.swift in Sources */,
5AE175E22667DA3F00D4DCE1 /* Sequence+Group.swift in Sources */,
5AE175EA2667DA3F00D4DCE1 /* CollectionViewSectionUpdate.swift in Sources */,
5AE175F92667DA3F00D4DCE1 /* CollectionViewBatchOperation.swift in Sources */,
5AE175EF2667DA3F00D4DCE1 /* ListSectionController.swift in Sources */,
Expand Down Expand Up @@ -881,7 +874,6 @@
5A31B8D526BAE95700036A3F /* BaseSectionFlowDelegateTests.swift in Sources */,
5A31B8D326BAE94E00036A3F /* ProtocolDefaultValuesSectionDropDelegateTests.swift in Sources */,
5A0B776626B146EC00B054D4 /* ListCollectionViewAdapterUICollectionViewDragDelegateTests.swift in Sources */,
5A0B777226B1A13B00B054D4 /* SequenceGroupTests.swift in Sources */,
5AA9D96A26AACACF00679D88 /* MockSectionDelegate.swift in Sources */,
5A0B778626B2AB7800B054D4 /* BaseSectionControllerTests.swift in Sources */,
5A0B777026B19EB300B054D4 /* MockListCollectionViewAdapterDataSource.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import UIKit
@available(iOS 10.0, *)
extension ListCollectionViewAdapter: UICollectionViewDataSourcePrefetching {
open func collectionView(_ collectionView: UICollectionView, prefetchItemsAt indexPaths: [IndexPath]) {
indexPaths.filter(\.isValid).group(by: \.section).forEach { sectionIndex, indexPaths in
let validIndexPaths = indexPaths.filter(\.isValid)
Dictionary(grouping: validIndexPaths, by: \.section).forEach { sectionIndex, indexPaths in
guard let dataSourcePrefetchingDelegate = dataSourcePrefetchingDelegate(at: sectionIndex) else {
return
}
Expand All @@ -13,7 +14,8 @@ extension ListCollectionViewAdapter: UICollectionViewDataSourcePrefetching {
}

open func collectionView(_ collectionView: UICollectionView, cancelPrefetchingForItemsAt indexPaths: [IndexPath]) {
indexPaths.filter(\.isValid).group(by: \.section).forEach { sectionIndex, indexPaths in
let validIndexPaths = indexPaths.filter(\.isValid)
Dictionary(grouping: validIndexPaths, by: \.section).forEach { sectionIndex, indexPaths in
guard let dataSourcePrefetchingDelegate = dataSourcePrefetchingDelegate(at: sectionIndex) else {
return
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,7 @@ open class ListCollectionViewAdapter: NSObject, CollectionViewAdapter {
private func filterDuplicateSectionIds(sections: [Section]) -> [Section] {
let filtered = sections.unique(by: \.id)
if filtered.count != sections.count {
let duplicateIds = sections
.group(by: \.id)
let duplicateIds = Dictionary(grouping: sections, by: \.id)
.filter { $0.value.count > 1 }
.map(\.key)
context.errorHandler.nonCritical(error: .duplicateSectionIds(duplicateIds))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import UIKit
@available(iOS 10.0, *)
extension SingleSectionCollectionViewAdapter: UICollectionViewDataSourcePrefetching {
open func collectionView(_ collectionView: UICollectionView, prefetchItemsAt indexPaths: [IndexPath]) {
indexPaths.filter(\.isValid).group(by: \.section).forEach { sectionIndex, indexPaths in
let validIndexPaths = indexPaths.filter(\.isValid)
Dictionary(grouping: validIndexPaths, by: \.section).forEach { sectionIndex, indexPaths in
guard let dataSourcePrefetchingDelegate = dataSourcePrefetchingDelegate(at: sectionIndex) else {
return
}
Expand All @@ -13,7 +14,8 @@ extension SingleSectionCollectionViewAdapter: UICollectionViewDataSourcePrefetch
}

open func collectionView(_ collectionView: UICollectionView, cancelPrefetchingForItemsAt indexPaths: [IndexPath]) {
indexPaths.filter(\.isValid).group(by: \.section).forEach { sectionIndex, indexPaths in
let validIndexPaths = indexPaths.filter(\.isValid)
Dictionary(grouping: validIndexPaths, by: \.section).forEach { sectionIndex, indexPaths in
guard let dataSourcePrefetchingDelegate = dataSourcePrefetchingDelegate(at: sectionIndex) else {
return
}
Expand Down
2 changes: 1 addition & 1 deletion SectionKit/Sources/Utility/Collection+Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ import Foundation

extension Collection {
/// A Boolean value indicating whether the collection is not empty.
@usableFromInline
@inlinable
internal var isNotEmpty: Bool { !isEmpty }
}
2 changes: 1 addition & 1 deletion SectionKit/Sources/Utility/IndexPath+IsValid.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Foundation

extension IndexPath {
@usableFromInline
@inlinable
internal var isValid: Bool {
count == 2 // precondition of the `section` property
}
Expand Down
13 changes: 0 additions & 13 deletions SectionKit/Sources/Utility/Sequence+Group.swift

This file was deleted.

2 changes: 1 addition & 1 deletion SectionKit/Sources/Utility/Sequence+Unique.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ extension Sequence {

- Returns: A sequence whose elements have unique values of the field referenced by `key`.
*/
@usableFromInline
@inlinable
internal func unique<T: Hashable>(by selector: (Iterator.Element) throws -> T) rethrows -> [Iterator.Element] {
var seen = Set<T>()
return try filter {
Expand Down
57 changes: 0 additions & 57 deletions SectionKit/Tests/Utility/SequenceGroupTests.swift

This file was deleted.