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>(
88
88
}
89
89
}
90
90
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 ) {
98
93
return 0 ;
99
94
}
100
95
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 ;
102
99
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 ;
118
102
}
119
103
}
104
+
105
+ return state . ids . length - 1 ;
120
106
}
121
107
122
108
return {
You can’t perform that action at this time.
0 commit comments