@@ -1179,7 +1179,7 @@ function initSearch(rawSearchIndex) {
11791179
11801180 /**
11811181 * This function checks if the object (`row`) generics match the given type (`elem`)
1182- * generics. If there are no generics on `row`, `defaultDistance` is returned.
1182+ * generics.
11831183 *
11841184 * @param {Row } row - The object to check.
11851185 * @param {QueryElement } elem - The element from the parsed query.
@@ -1196,82 +1196,82 @@ function initSearch(rawSearchIndex) {
11961196 // This search engine implements order-agnostic unification. There
11971197 // should be no missing duplicates (generics have "bag semantics"),
11981198 // and the row is allowed to have extras.
1199- if ( elem . generics . length > 0 && row . generics . length >= elem . generics . length ) {
1200- const elems = new Map ( ) ;
1201- const addEntryToElems = function addEntryToElems ( entry ) {
1202- if ( entry . id === - 1 ) {
1203- // Pure generic, needs to check into it.
1204- for ( const inner_entry of entry . generics ) {
1205- addEntryToElems ( inner_entry ) ;
1206- }
1207- return ;
1208- }
1209- let currentEntryElems ;
1210- if ( elems . has ( entry . id ) ) {
1211- currentEntryElems = elems . get ( entry . id ) ;
1212- } else {
1213- currentEntryElems = [ ] ;
1214- elems . set ( entry . id , currentEntryElems ) ;
1199+ if ( elem . generics . length <= 0 || row . generics . length < elem . generics . length ) {
1200+ return false ;
1201+ }
1202+ const elems = new Map ( ) ;
1203+ const addEntryToElems = function addEntryToElems ( entry ) {
1204+ if ( entry . id === - 1 ) {
1205+ // Pure generic, needs to check into it.
1206+ for ( const inner_entry of entry . generics ) {
1207+ addEntryToElems ( inner_entry ) ;
12151208 }
1216- currentEntryElems . push ( entry ) ;
1217- } ;
1218- for ( const entry of row . generics ) {
1219- addEntryToElems ( entry ) ;
1209+ return ;
12201210 }
1221- // We need to find the type that matches the most to remove it in order
1222- // to move forward.
1223- const handleGeneric = generic => {
1224- if ( ! elems . has ( generic . id ) ) {
1225- return false ;
1226- }
1227- const matchElems = elems . get ( generic . id ) ;
1228- const matchIdx = matchElems . findIndex ( tmp_elem => {
1229- if ( generic . generics . length > 0 && ! checkGenerics ( tmp_elem , generic ) ) {
1230- return false ;
1231- }
1232- return typePassesFilter ( generic . typeFilter , tmp_elem . ty ) ;
1233- } ) ;
1234- if ( matchIdx === - 1 ) {
1235- return false ;
1236- }
1237- matchElems . splice ( matchIdx , 1 ) ;
1238- if ( matchElems . length === 0 ) {
1239- elems . delete ( generic . id ) ;
1240- }
1241- return true ;
1242- } ;
1243- // To do the right thing with type filters, we first process generics
1244- // that have them, removing matching ones from the "bag," then do the
1245- // ones with no type filter, which can match any entry regardless of its
1246- // own type.
1247- for ( const generic of elem . generics ) {
1248- if ( generic . typeFilter === TY_PRIMITIVE &&
1249- generic . id === typeNameIdOfArrayOrSlice ) {
1250- const genericArray = {
1251- id : typeNameIdOfArray ,
1252- typeFilter : TY_PRIMITIVE ,
1253- generics : generic . generics ,
1254- } ;
1255- const genericSlice = {
1256- id : typeNameIdOfSlice ,
1257- typeFilter : TY_PRIMITIVE ,
1258- generics : generic . generics ,
1259- } ;
1260- if ( ! handleGeneric ( genericArray ) && ! handleGeneric ( genericSlice ) ) {
1261- return false ;
1262- }
1263- } else if ( generic . typeFilter !== - 1 && ! handleGeneric ( generic ) ) {
1211+ let currentEntryElems ;
1212+ if ( elems . has ( entry . id ) ) {
1213+ currentEntryElems = elems . get ( entry . id ) ;
1214+ } else {
1215+ currentEntryElems = [ ] ;
1216+ elems . set ( entry . id , currentEntryElems ) ;
1217+ }
1218+ currentEntryElems . push ( entry ) ;
1219+ } ;
1220+ for ( const entry of row . generics ) {
1221+ addEntryToElems ( entry ) ;
1222+ }
1223+ // We need to find the type that matches the most to remove it in order
1224+ // to move forward.
1225+ const handleGeneric = generic => {
1226+ if ( ! elems . has ( generic . id ) ) {
1227+ return false ;
1228+ }
1229+ const matchElems = elems . get ( generic . id ) ;
1230+ const matchIdx = matchElems . findIndex ( tmp_elem => {
1231+ if ( generic . generics . length > 0 && ! checkGenerics ( tmp_elem , generic ) ) {
12641232 return false ;
12651233 }
1234+ return typePassesFilter ( generic . typeFilter , tmp_elem . ty ) ;
1235+ } ) ;
1236+ if ( matchIdx === - 1 ) {
1237+ return false ;
12661238 }
1267- for ( const generic of elem . generics ) {
1268- if ( generic . typeFilter === - 1 && ! handleGeneric ( generic ) ) {
1239+ matchElems . splice ( matchIdx , 1 ) ;
1240+ if ( matchElems . length === 0 ) {
1241+ elems . delete ( generic . id ) ;
1242+ }
1243+ return true ;
1244+ } ;
1245+ // To do the right thing with type filters, we first process generics
1246+ // that have them, removing matching ones from the "bag," then do the
1247+ // ones with no type filter, which can match any entry regardless of its
1248+ // own type.
1249+ for ( const generic of elem . generics ) {
1250+ if ( generic . typeFilter === TY_PRIMITIVE &&
1251+ generic . id === typeNameIdOfArrayOrSlice ) {
1252+ const genericArray = {
1253+ id : typeNameIdOfArray ,
1254+ typeFilter : TY_PRIMITIVE ,
1255+ generics : generic . generics ,
1256+ } ;
1257+ const genericSlice = {
1258+ id : typeNameIdOfSlice ,
1259+ typeFilter : TY_PRIMITIVE ,
1260+ generics : generic . generics ,
1261+ } ;
1262+ if ( ! handleGeneric ( genericArray ) && ! handleGeneric ( genericSlice ) ) {
12691263 return false ;
12701264 }
1265+ } else if ( generic . typeFilter !== - 1 && ! handleGeneric ( generic ) ) {
1266+ return false ;
12711267 }
1272- return true ;
12731268 }
1274- return false ;
1269+ for ( const generic of elem . generics ) {
1270+ if ( generic . typeFilter === - 1 && ! handleGeneric ( generic ) ) {
1271+ return false ;
1272+ }
1273+ }
1274+ return true ;
12751275 }
12761276
12771277 /**
0 commit comments