@@ -1076,6 +1076,34 @@ function isPathSeparator(c) {
1076
1076
return c === ":" || c === " " ;
1077
1077
}
1078
1078
1079
+ /**
1080
+ * Given an array and an ascending list of indices,
1081
+ * efficiently removes each index in the array.
1082
+ *
1083
+ * @template T
1084
+ * @param {Array<T> } a
1085
+ * @param {Array<number> } idxList
1086
+ */
1087
+ function removeIdxListAsc ( a , idxList ) {
1088
+ if ( idxList . length === 0 ) {
1089
+ return ;
1090
+ }
1091
+ let removed = 0 ;
1092
+ let i = idxList [ 0 ] ;
1093
+ let nextToRemove = idxList [ 0 ] ;
1094
+ while ( i < a . length - idxList . length ) {
1095
+ while ( i === nextToRemove && removed < idxList . length ) {
1096
+ removed ++ ;
1097
+ i ++ ;
1098
+ nextToRemove = idxList [ removed ] ;
1099
+ }
1100
+ a [ i ] = a [ i + removed ] ;
1101
+ i ++ ;
1102
+ }
1103
+ // truncate array
1104
+ a . length -= idxList . length ;
1105
+ }
1106
+
1079
1107
/**
1080
1108
* @template T
1081
1109
*/
@@ -2610,7 +2638,7 @@ class DocSearch {
2610
2638
*/
2611
2639
const transformResults = ( results , typeInfo , duplicates ) => {
2612
2640
/** @type {rustdoc.ResultObject[] } */
2613
- let out = [ ] ;
2641
+ const out = [ ] ;
2614
2642
2615
2643
// if we match a trait-associated item, we want to go back and
2616
2644
// remove all the items that are their equivalent but in an impl block.
@@ -2708,16 +2736,9 @@ class DocSearch {
2708
2736
list . push ( out . length ) ;
2709
2737
traitImplIdxMap . set ( obj . traitPath , list ) ;
2710
2738
} else {
2711
- // FIXME: this is `O(n*m)` because we're repeatedly
2712
- // shifting with Array.splice, but could be `O(n+m)` if
2713
- // we did the shifting manually in a more clever way.
2714
2739
const toRemove = traitImplIdxMap . get ( obj . fullPath ) ;
2715
2740
if ( toRemove ) {
2716
- // iterate in reverse order so we don't shift the indexes
2717
- for ( let i = toRemove . length - 1 ; i >= 0 ; i -- ) {
2718
- const rmIdx = toRemove [ i ] ;
2719
- out = out . splice ( rmIdx , 1 ) ;
2720
- }
2741
+ removeIdxListAsc ( out , toRemove ) ;
2721
2742
}
2722
2743
traitImplIdxMap . delete ( obj . fullPath ) ;
2723
2744
}
0 commit comments