Skip to content

Commit 91fe7c3

Browse files
committed
Merge pull request lbrndnr#73 from colinta/cg/compile-times
Decrease compile times
2 parents be2d4d6 + a56f1df commit 91fe7c3

File tree

3 files changed

+23
-12
lines changed

3 files changed

+23
-12
lines changed

ImagePickerSheetController/ImagePickerSheetController/ImagePickerSheetController.swift

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -316,16 +316,25 @@ public class ImagePickerSheetController: UIViewController {
316316
let maxHeight: CGFloat = 400
317317
let maxImageWidth = sheetController.preferredSheetWidth - 2 * previewCollectionViewInset
318318

319-
let assetRatios = assets.map { CGSize(width: max($0.pixelHeight, $0.pixelWidth), height: min($0.pixelHeight, $0.pixelWidth)) }
320-
.map { $0.height / $0.width }
321-
322-
let assetHeights = assetRatios.map { $0 * maxImageWidth }
323-
.filter { $0 < maxImageWidth && $0 < maxHeight } // Make sure the preview isn't too high eg for squares
319+
let assetRatios = assets.map { (asset: PHAsset) -> CGSize in
320+
CGSize(width: max(asset.pixelHeight, asset.pixelWidth), height: min(asset.pixelHeight, asset.pixelWidth))
321+
}.map { (size: CGSize) -> CGFloat in
322+
size.height / size.width
323+
}
324+
325+
let assetHeights = assetRatios.map { (ratio: CGFloat) -> CGFloat in ratio * maxImageWidth }
326+
.filter { (height: CGFloat) -> Bool in height < maxImageWidth && height < maxHeight } // Make sure the preview isn't too high eg for squares
324327
.sort(>)
325-
let assetHeight = ceil(assetHeights.first ?? 0)
326-
328+
let assetHeight: CGFloat
329+
if let first = assetHeights.first {
330+
assetHeight = first
331+
}
332+
else {
333+
assetHeight = 0
334+
}
335+
327336
// Just a sanity check, to make sure this doesn't exceed 400 points
328-
let scaledHeight = max(min(assetHeight, maxHeight), 200)
337+
let scaledHeight: CGFloat = max(min(assetHeight, maxHeight), 200)
329338
maximumPreviewHeight = scaledHeight + 2 * previewCollectionViewInset
330339
}
331340

ImagePickerSheetController/ImagePickerSheetController/Sheet/Preview/PreviewCollectionView.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ import UIKit
1111
class PreviewCollectionView: UICollectionView {
1212

1313
var bouncing: Bool {
14-
return contentOffset.x < -contentInset.left || contentOffset.x + frame.width > contentSize.width + contentInset.right
14+
if contentOffset.x < -contentInset.left { return true }
15+
if contentOffset.x + frame.width > contentSize.width + contentInset.right { return true }
16+
return false
1517
}
1618

1719
var imagePreviewLayout: PreviewCollectionViewLayout {

ImagePickerSheetController/ImagePickerSheetController/Sheet/SheetController.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,9 @@ class SheetController: NSObject {
7272

7373
private func allIndexPaths() -> [NSIndexPath] {
7474
let s = numberOfSections()
75-
return (0 ..< s).map { (self.numberOfItemsInSection($0), $0) }
76-
.flatMap { numberOfItems, section in
77-
(0 ..< numberOfItems).map { NSIndexPath(forItem: $0, inSection: section) }
75+
return (0 ..< s).map { (section: Int) -> (Int, Int) in (self.numberOfItemsInSection(section), section) }
76+
.flatMap { (numberOfItems: Int, section: Int) -> [NSIndexPath] in
77+
(0 ..< numberOfItems).map { (item: Int) -> NSIndexPath in NSIndexPath(forItem: item, inSection: section) }
7878
}
7979
}
8080

0 commit comments

Comments
 (0)