@@ -846,26 +846,38 @@ function defocusSearchBar() {
846
846
if ( val . generics . length > 0 ) {
847
847
if ( obj . length > GENERICS_DATA &&
848
848
obj [ GENERICS_DATA ] . length >= val . generics . length ) {
849
- var elems = obj [ GENERICS_DATA ] . slice ( 0 ) ;
849
+ var elems = { } ;
850
+ var elength = object [ GENERICS_DATA ] . length ;
851
+ for ( var x = 0 ; x < elength ; ++ x ) {
852
+ elems [ getObjectNameFromId ( obj [ GENERICS_DATA ] [ x ] ) ] += 1 ;
853
+ }
850
854
var total = 0 ;
851
855
var done = 0 ;
852
856
// We need to find the type that matches the most to remove it in order
853
857
// to move forward.
854
858
var vlength = val . generics . length ;
855
- for ( var y = 0 ; y < vlength ; ++ y ) {
856
- var lev = { pos : - 1 , lev : MAX_LEV_DISTANCE + 1 } ;
857
- var firstGeneric = getObjectNameFromId ( val . generics [ y ] ) ;
858
- for ( var x = 0 , elength = elems . length ; x < elength ; ++ x ) {
859
- var tmp_lev = levenshtein ( getObjectNameFromId ( elems [ x ] ) ,
860
- firstGeneric ) ;
861
- if ( tmp_lev < lev . lev ) {
862
- lev . lev = tmp_lev ;
863
- lev . pos = x ;
859
+ for ( var x = 0 ; x < vlength ; ++ x ) {
860
+ var lev = MAX_LEV_DISTANCE + 1 ;
861
+ var firstGeneric = getObjectNameFromId ( val . generics [ x ] ) ;
862
+ var match = undefined ;
863
+ if ( elems [ firstGeneric ] ) {
864
+ match = firstGeneric ;
865
+ lev = 0 ;
866
+ } else {
867
+ for ( var elem_name in elems ) {
868
+ var tmp_lev = levenshtein ( elem_name , firstGeneric ) ;
869
+ if ( tmp_lev < lev ) {
870
+ lev = tmp_lev ;
871
+ match = elem_name ;
872
+ }
864
873
}
865
874
}
866
- if ( lev . pos !== - 1 ) {
867
- elems . splice ( lev . pos , 1 ) ;
868
- total += lev . lev ;
875
+ if ( match !== undefined ) {
876
+ elems [ match ] -= 1 ;
877
+ if ( elems [ match ] == 0 ) {
878
+ delete elems [ match ] ;
879
+ }
880
+ total += lev ;
869
881
done += 1 ;
870
882
} else {
871
883
return MAX_LEV_DISTANCE + 1 ;
@@ -880,25 +892,27 @@ function defocusSearchBar() {
880
892
// Check for type name and type generics (if any).
881
893
function checkType ( obj , val , literalSearch ) {
882
894
var lev_distance = MAX_LEV_DISTANCE + 1 ;
883
- var len , x , y , e_len , firstGeneric ;
895
+ var len , x , firstGeneric ;
884
896
if ( obj [ NAME ] === val . name ) {
885
897
if ( literalSearch === true ) {
886
898
if ( val . generics && val . generics . length !== 0 ) {
887
899
if ( obj . length > GENERICS_DATA &&
888
900
obj [ GENERICS_DATA ] . length >= val . generics . length ) {
889
- var elems = obj [ GENERICS_DATA ] . slice ( 0 ) ;
890
- var allFound = true ;
901
+ var elems = { } ;
902
+ len = obj [ GENERICS_DATA ] . length ;
903
+ for ( x = 0 ; x < len ; ++ x ) {
904
+ elems [ getObjectNameFromId ( obj [ GENERICS_DATA ] [ x ] ) ] += 1 ;
905
+ }
891
906
907
+ var allFound = true ;
892
908
len = val . generics . length ;
893
- for ( y = 0 ; allFound === true && y < len ; ++ y ) {
894
- allFound = false ;
895
- firstGeneric = getObjectNameFromId ( val . generics [ y ] ) ;
896
- e_len = elems . length ;
897
- for ( x = 0 ; allFound === false && x < e_len ; ++ x ) {
898
- allFound = getObjectNameFromId ( elems [ x ] ) === firstGeneric ;
899
- }
900
- if ( allFound === true ) {
901
- elems . splice ( x - 1 , 1 ) ;
909
+ for ( x = 0 ; x < len ; ++ x ) {
910
+ firstGeneric = getObjectNameFromId ( val . generics [ x ] ) ;
911
+ if ( elems [ firstGeneric ] ) {
912
+ elems [ firstGeneric ] -= 1 ;
913
+ } else {
914
+ allFound = false ;
915
+ break ;
902
916
}
903
917
}
904
918
if ( allFound === true ) {
@@ -1066,13 +1080,6 @@ function defocusSearchBar() {
1066
1080
return false ;
1067
1081
}
1068
1082
1069
- function generateId ( ty ) {
1070
- if ( ty . parent && ty . parent . name ) {
1071
- return itemTypes [ ty . ty ] + ty . path + ty . parent . name + ty . name ;
1072
- }
1073
- return itemTypes [ ty . ty ] + ty . path + ty . name ;
1074
- }
1075
-
1076
1083
function createAliasFromItem ( item ) {
1077
1084
return {
1078
1085
crate : item . crate ,
@@ -1158,7 +1165,7 @@ function defocusSearchBar() {
1158
1165
in_args = findArg ( searchIndex [ i ] , val , true , typeFilter ) ;
1159
1166
returned = checkReturned ( searchIndex [ i ] , val , true , typeFilter ) ;
1160
1167
ty = searchIndex [ i ] ;
1161
- fullId = generateId ( ty ) ;
1168
+ fullId = ty . id ;
1162
1169
1163
1170
if ( searchWords [ i ] === val . name
1164
1171
&& typePassesFilter ( typeFilter , searchIndex [ i ] . ty )
@@ -1208,7 +1215,7 @@ function defocusSearchBar() {
1208
1215
if ( ! type ) {
1209
1216
continue ;
1210
1217
}
1211
- fullId = generateId ( ty ) ;
1218
+ fullId = ty . id ;
1212
1219
1213
1220
returned = checkReturned ( ty , output , true , NO_TYPE_FILTER ) ;
1214
1221
if ( output . name === "*" || returned === true ) {
@@ -1292,7 +1299,7 @@ function defocusSearchBar() {
1292
1299
var index = - 1 ;
1293
1300
// we want lev results to go lower than others
1294
1301
lev = MAX_LEV_DISTANCE + 1 ;
1295
- fullId = generateId ( ty ) ;
1302
+ fullId = ty . id ;
1296
1303
1297
1304
if ( searchWords [ j ] . indexOf ( split [ i ] ) > - 1 ||
1298
1305
searchWords [ j ] . indexOf ( val ) > - 1 ||
@@ -1825,6 +1832,13 @@ function defocusSearchBar() {
1825
1832
showResults ( execSearch ( query , index , filterCrates ) ) ;
1826
1833
}
1827
1834
1835
+ function generateId ( ty ) {
1836
+ if ( ty . parent && ty . parent . name ) {
1837
+ return itemTypes [ ty . ty ] + ty . path + ty . parent . name + ty . name ;
1838
+ }
1839
+ return itemTypes [ ty . ty ] + ty . path + ty . name ;
1840
+ }
1841
+
1828
1842
function buildIndex ( rawSearchIndex ) {
1829
1843
searchIndex = [ ] ;
1830
1844
var searchWords = [ ] ;
@@ -1837,14 +1851,18 @@ function defocusSearchBar() {
1837
1851
var crateSize = 0 ;
1838
1852
1839
1853
searchWords . push ( crate ) ;
1840
- searchIndex . push ( {
1854
+ var crateRow = {
1841
1855
crate : crate ,
1842
1856
ty : 1 , // == ExternCrate
1843
1857
name : crate ,
1844
1858
path : "" ,
1845
1859
desc : rawSearchIndex [ crate ] . doc ,
1860
+ parent : undefined ,
1846
1861
type : null ,
1847
- } ) ;
1862
+ id : "" ,
1863
+ } ;
1864
+ crateRow . id = generateId ( crateRow ) ;
1865
+ searchIndex . push ( crateRow ) ;
1848
1866
currentIndex += 1 ;
1849
1867
1850
1868
// an array of (Number) item types
@@ -1890,7 +1908,9 @@ function defocusSearchBar() {
1890
1908
desc : itemDescs [ i ] ,
1891
1909
parent : itemParentIdxs [ i ] > 0 ? paths [ itemParentIdxs [ i ] - 1 ] : undefined ,
1892
1910
type : itemFunctionSearchTypes [ i ] ,
1911
+ id : "" ,
1893
1912
} ;
1913
+ row . id = generateId ( row ) ;
1894
1914
searchIndex . push ( row ) ;
1895
1915
if ( typeof row . name === "string" ) {
1896
1916
var word = row . name . toLowerCase ( ) ;
0 commit comments