File tree Expand file tree Collapse file tree 1 file changed +9
-23
lines changed
Expand file tree Collapse file tree 1 file changed +9
-23
lines changed Original file line number Diff line number Diff line change @@ -88,35 +88,21 @@ export function createSortedStateAdapter<T>(
8888 }
8989 }
9090
91- function findTargetIndex (
92- state : R ,
93- model : T ,
94- left = 0 ,
95- right = state . ids . length - 1
96- ) {
97- if ( right === - 1 ) {
91+ function findTargetIndex ( state : R , model : T ) {
92+ if ( state . ids . length === 0 ) {
9893 return 0 ;
9994 }
10095
101- let middle : number ;
96+ for ( let i = 0 ; i < state . ids . length ; i ++ ) {
97+ const entity = state . entities [ state . ids [ i ] ] ;
98+ const isSmaller = sort ( model , entity ) < 0 ;
10299
103- while ( true ) {
104- middle = Math . floor ( ( left + right ) / 2 ) ;
105-
106- const result = sort ( state . entities [ state . ids [ middle ] ] , model ) ;
107-
108- if ( result === 0 ) {
109- return middle ;
110- } else if ( result < 0 ) {
111- left = middle + 1 ;
112- } else {
113- right = middle - 1 ;
114- }
115-
116- if ( left > right ) {
117- return state . ids . length - 1 ;
100+ if ( isSmaller ) {
101+ return i ;
118102 }
119103 }
104+
105+ return state . ids . length - 1 ;
120106 }
121107
122108 return {
You can’t perform that action at this time.
0 commit comments