@@ -786,7 +786,7 @@ class VirtualizedList extends StateSafePureComponent<
786786 _pushCells (
787787 cells : Array < Object > ,
788788 stickyHeaderIndices : Array < number > ,
789- stickyIndicesFromProps : Set < number > ,
789+ stickyIndicesFromProps : null | Set < number > ,
790790 first : number ,
791791 last : number ,
792792 inversionStyle : StyleProp < ViewStyle > ,
@@ -814,7 +814,10 @@ class VirtualizedList extends StateSafePureComponent<
814814 const key = VirtualizedList . _keyExtractor ( item , ii , this . props ) ;
815815
816816 this . _indicesToKeys . set ( ii , key ) ;
817- if ( stickyIndicesFromProps . has ( ii + stickyOffset ) ) {
817+ if (
818+ stickyIndicesFromProps != null &&
819+ stickyIndicesFromProps . has ( ii + stickyOffset )
820+ ) {
818821 stickyHeaderIndices . push ( cells . length ) ;
819822 }
820823
@@ -945,12 +948,16 @@ class VirtualizedList extends StateSafePureComponent<
945948 : styles . verticallyInverted
946949 : null ;
947950 const cells : Array < any | React . Node > = [ ] ;
948- const stickyIndicesFromProps = new Set ( this . props . stickyHeaderIndices ) ;
951+ // Avoid allocating a Set on every render when no sticky headers are
952+ // configured (the common case).
953+ const stickyHeaderIndicesProp = this . props . stickyHeaderIndices ;
954+ const stickyIndicesFromProps =
955+ stickyHeaderIndicesProp != null ? new Set ( stickyHeaderIndicesProp ) : null ;
949956 const stickyHeaderIndices = [ ] ;
950957
951958 // 1. Add cell for ListHeaderComponent
952959 if ( ListHeaderComponent ) {
953- if ( stickyIndicesFromProps . has ( 0 ) ) {
960+ if ( stickyIndicesFromProps != null && stickyIndicesFromProps . has ( 0 ) ) {
954961 stickyHeaderIndices . push ( 0 ) ;
955962 }
956963 const element = isValidElement ( ListHeaderComponent ) ? (
@@ -1232,6 +1239,8 @@ class VirtualizedList extends StateSafePureComponent<
12321239 }
12331240 }
12341241
1242+ _cachedOrientation: ?ListOrientation = null ;
1243+ _cachedOrientationHorizontal: ?boolean = null ;
12351244 _cellRefs: { [ string ] : null | CellRenderer < any > } = { } ;
12361245 _fillRateHelper: FillRateHelper ;
12371246 _listMetrics: ListMetricsAggregator = new ListMetricsAggregator ( ) ;
@@ -1553,10 +1562,23 @@ class VirtualizedList extends StateSafePureComponent<
15531562 }
15541563
15551564 _orientation ( ) : ListOrientation {
1556- return {
1557- horizontal : horizontalOrDefault ( this . props . horizontal ) ,
1558- rtl : I18nManager . isRTL ,
1559- } ;
1565+ // The orientation is stable for the lifetime of the list unless the
1566+ // `horizontal` prop changes (I18nManager.isRTL only changes on app
1567+ // reload). Cache the object to avoid allocating it on the scroll path.
1568+ const horizontal = horizontalOrDefault ( this . props . horizontal ) ;
1569+ let cachedOrientation = this . _cachedOrientation ;
1570+ if (
1571+ cachedOrientation == null ||
1572+ this . _cachedOrientationHorizontal !== horizontal
1573+ ) {
1574+ cachedOrientation = {
1575+ horizontal,
1576+ rtl : I18nManager . isRTL ,
1577+ } ;
1578+ this . _cachedOrientation = cachedOrientation ;
1579+ this . _cachedOrientationHorizontal = horizontal ;
1580+ }
1581+ return cachedOrientation ;
15601582 }
15611583
15621584 _maybeCallOnEdgeReached ( ) {
0 commit comments