@@ -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
*/
@@ -2615,7 +2643,7 @@ class DocSearch {
2615
2643
*/
2616
2644
const transformResults = ( results , typeInfo , duplicates ) => {
2617
2645
/** @type {rustdoc.ResultObject[] } */
2618
- let out = [ ] ;
2646
+ const out = [ ] ;
2619
2647
2620
2648
// if we match a trait-associated item, we want to go back and
2621
2649
// remove all the items that are their equivalent but in an impl block.
@@ -2712,16 +2740,9 @@ class DocSearch {
2712
2740
list . push ( out . length ) ;
2713
2741
traitImplIdxMap . set ( obj . traitPath , list ) ;
2714
2742
} else {
2715
- // FIXME: this is `O(n*m)` because we're repeatedly
2716
- // shifting with Array.splice, but could be `O(n+m)` if
2717
- // we did the shifting manually in a more clever way.
2718
2743
const toRemoveList = traitImplIdxMap . get ( obj . fullPath ) ;
2719
2744
if ( toRemoveList ) {
2720
- // iterate in reverse order so we don't shift the indexes
2721
- for ( let i = toRemoveList . length - 1 ; i >= 0 ; i -- ) {
2722
- const rmIdx = toRemoveList [ i ] ;
2723
- out = out . splice ( rmIdx , 1 ) ;
2724
- }
2745
+ removeIdxListAsc ( out , toRemoveList ) ;
2725
2746
}
2726
2747
traitImplIdxMap . delete ( obj . fullPath ) ;
2727
2748
}
0 commit comments