From 8bccac9a7940ca301e1db49faf777b9e0b3a1d9a Mon Sep 17 00:00:00 2001 From: zhongwuzw Date: Mon, 29 Jan 2018 20:28:55 -0800 Subject: [PATCH] Optimize SEL search efficiency Summary: Optimize `SEL` search efficiency, reduced the time complexity from O (n) to O (1). Not need tests. - [x] All tests pass. Demo project builds and runs. - [x] I added tests, an experiment, or detailed why my change isn't tested. - [x] I added an entry to the `CHANGELOG.md` for any breaking changes, enhancements, or bug fixes. - [x] I have reviewed the [contributing guide](https://github.com/Instagram/IGListKit/blob/master/.github/CONTRIBUTING.md) Closes https://github.com/Instagram/IGListKit/pull/1055 Differential Revision: D6839942 Pulled By: rnystrom fbshipit-source-id: 911755d6f8a4cd79b387423a51b6ea44cc7a2a07 --- CHANGELOG.md | 2 ++ Source/Internal/IGListAdapterProxy.m | 8 +++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index de605624..d7212b5f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,6 +23,8 @@ The changelog for `IGListKit`. Also see the [releases](https://github.com/instag - Added new `transitionDelegate` API to give `IGListSectionController`s control to customize initial and final `UICollectionViewLayoutAttribute`s. Includes automatic integration with `IGListCollectionViewLayout`. Sue Suhan Ma [(26924ec)](https://github.com/Instagram/IGListKit/commit/26924ec3b665d37aeed7e28887e4221a7f3501b1) +- Reordered position of intercepted selector in `IGListAdapterProxy`'s `isInterceptedSelector` method to reduce overall consumption of compare. [zhongwuzw](https://github.com/zhongwu) [(#1055)](https://github.com/Instagram/IGListKit/pull/1055) + ### Fixes - Duplicate objects for initial data source setup filtered out. [Mikhail Vashlyaev](https://github.com/yemodin) [(#993](https://github.com/Instagram/IGListKit/pull/993) diff --git a/Source/Internal/IGListAdapterProxy.m b/Source/Internal/IGListAdapterProxy.m index 7b0bc214..9fa6abc4 100644 --- a/Source/Internal/IGListAdapterProxy.m +++ b/Source/Internal/IGListAdapterProxy.m @@ -18,10 +18,15 @@ */ static BOOL isInterceptedSelector(SEL sel) { return ( + // UIScrollViewDelegate + sel == @selector(scrollViewDidScroll:) || + sel == @selector(scrollViewWillBeginDragging:) || + sel == @selector(scrollViewDidEndDragging:willDecelerate:) || + sel == @selector(scrollViewDidEndDecelerating:) || // UICollectionViewDelegate - sel == @selector(collectionView:didSelectItemAtIndexPath:) || sel == @selector(collectionView:willDisplayCell:forItemAtIndexPath:) || sel == @selector(collectionView:didEndDisplayingCell:forItemAtIndexPath:) || + sel == @selector(collectionView:didSelectItemAtIndexPath:) || sel == @selector(collectionView:didHighlightItemAtIndexPath:) || sel == @selector(collectionView:didUnhighlightItemAtIndexPath:) || // UICollectionViewDelegateFlowLayout @@ -31,6 +36,7 @@ static BOOL isInterceptedSelector(SEL sel) { sel == @selector(collectionView:layout:minimumLineSpacingForSectionAtIndex:) || sel == @selector(collectionView:layout:referenceSizeForFooterInSection:) || sel == @selector(collectionView:layout:referenceSizeForHeaderInSection:) || + sel == @selector(collectionView:layout:referenceSizeForHeaderInSection:) || // UIScrollViewDelegate sel == @selector(scrollViewDidScroll:) || sel == @selector(scrollViewWillBeginDragging:) ||