@@ -1076,6 +1076,34 @@ function isPathSeparator(c) {
10761076 return c === ":" || c === " " ;
10771077}
10781078
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+
10791107/**
10801108 * @template T
10811109 */
@@ -2616,7 +2644,7 @@ class DocSearch {
26162644 */
26172645 const transformResults = ( results , typeInfo , duplicates ) => {
26182646 /** @type {rustdoc.ResultObject[] } */
2619- let out = [ ] ;
2647+ const out = [ ] ;
26202648
26212649 // if we match a trait-associated item, we want to go back and
26222650 // remove all the items that are their equivalent but in an impl block.
@@ -2713,16 +2741,9 @@ class DocSearch {
27132741 list . push ( out . length ) ;
27142742 traitImplIdxMap . set ( obj . traitPath , list ) ;
27152743 } else {
2716- // FIXME: this is `O(n*m)` because we're repeatedly
2717- // shifting with Array.splice, but could be `O(n+m)` if
2718- // we did the shifting manually in a more clever way.
27192744 const toRemove = traitImplIdxMap . get ( obj . fullPath ) ;
27202745 if ( toRemove ) {
2721- // iterate in reverse order so we don't shift the indexes
2722- for ( let i = toRemove . length - 1 ; i >= 0 ; i -- ) {
2723- const rmIdx = toRemove [ i ] ;
2724- out = out . splice ( rmIdx , 1 ) ;
2725- }
2746+ removeIdxListAsc ( out , toRemove ) ;
27262747 }
27272748 traitImplIdxMap . delete ( obj . fullPath ) ;
27282749 }
0 commit comments