Skip to content

Commit 0a59952

Browse files
committed
Fix nitpicks and a random perf problem that I found
1 parent 69c87b3 commit 0a59952

File tree

5 files changed

+54
-47
lines changed

5 files changed

+54
-47
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"dependencies": {
33
"browser-ui-test": "^0.21.1",
44
"es-check": "^6.2.1",
5-
"eslint": "^8.6.0",
5+
"eslint": "^8.57.1",
66
"eslint-js": "github:eslint/js",
77
"typescript": "^5.8.3"
88
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
8.6.0
1+
8.57.1

src/librustdoc/html/static/js/search.js

Lines changed: 52 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -880,7 +880,7 @@ function createQueryElement(query, parserState, name, generics, isInGenerics) {
880880
*/
881881
function makePrimitiveElement(name, extra) {
882882
return Object.assign({
883-
name: name,
883+
name,
884884
id: null,
885885
fullPath: [name],
886886
pathWithoutLast: [],
@@ -1200,33 +1200,43 @@ class DocSearch {
12001200
if (!nn) {
12011201
return;
12021202
}
1203+
// Each of these identifiers are used specially by
1204+
// type-driven search.
12031205
const [
1206+
// output is the special associated type that goes
1207+
// after the arrow: the type checker desugars
1208+
// the path `Fn(a) -> b` into `Fn<Output=b, (a)>`
12041209
output,
1210+
// fn, fnmut, and fnonce all match `->`
12051211
fn,
12061212
fnMut,
12071213
fnOnce,
1214+
hof,
1215+
// array and slice both match `[]`
12081216
array,
12091217
slice,
12101218
arrayOrSlice,
1219+
// tuple and unit both match `()`
12111220
tuple,
12121221
unit,
12131222
tupleOrUnit,
1223+
// reference matches `&`
12141224
reference,
1215-
hof,
1225+
// never matches `!`
12161226
never,
12171227
] = await Promise.all([
12181228
nn.search("output"),
12191229
nn.search("fn"),
12201230
nn.search("fnmut"),
12211231
nn.search("fnonce"),
1232+
nn.search("->"),
12221233
nn.search("array"),
12231234
nn.search("slice"),
12241235
nn.search("[]"),
12251236
nn.search("tuple"),
12261237
nn.search("unit"),
12271238
nn.search("()"),
12281239
nn.search("reference"),
1229-
nn.search("->"),
12301240
nn.search("never"),
12311241
]);
12321242
/**
@@ -4232,9 +4242,8 @@ class DocSearch {
42324242
unpackPostingsListAll(inputs),
42334243
unpackPostingsListAll(output),
42344244
]);
4235-
const results = [];
4245+
const resultPromises = [];
42364246
let checkCounter = 0;
4237-
let maxDist = 0;
42384247
for (const [inputsPostingList, inputs] of allInputs) {
42394248
for (const [outputPostingList, output] of allOutput) {
42404249
const postingList = inputsPostingList.intersection(outputPostingList);
@@ -4243,51 +4252,49 @@ class DocSearch {
42434252
if ((checkCounter & 0x7F) === 0) {
42444253
await yieldToBrowser();
42454254
}
4246-
const fnData = await this.getFunctionData(id);
4247-
if (!fnData || !fnData.functionSignature) {
4248-
continue;
4249-
}
4250-
if (fnData.elemCount > maxDist) {
4251-
if (results.length > 200) {
4252-
continue;
4253-
} else {
4254-
maxDist = fnData.elemCount;
4255+
resultPromises.push(this.getFunctionData(id).then(async (fnData) => {
4256+
if (!fnData || !fnData.functionSignature) {
4257+
return null;
42554258
}
4256-
}
4257-
const functionSignature = fnData.functionSignature;
4258-
if (!unifyFunctionTypes(
4259-
functionSignature.inputs,
4260-
inputs,
4261-
functionSignature.where_clause,
4262-
null,
4263-
mgens => {
4264-
return !!unifyFunctionTypes(
4265-
functionSignature.output,
4266-
output,
4267-
functionSignature.where_clause,
4268-
mgens,
4269-
checkTypeMgensForConflict,
4270-
0, // unboxing depth
4271-
);
4272-
},
4273-
0, // unboxing depth
4274-
)) {
4275-
continue;
4276-
}
4277-
results.push({
4278-
id,
4279-
dist: fnData.elemCount,
4280-
path_dist: 0,
4281-
index: -1,
4282-
elems: inputs,
4283-
returned: output,
4284-
is_alias: false,
4285-
});
4259+
checkCounter += 1;
4260+
if ((checkCounter & 0x7F) === 0) {
4261+
await yieldToBrowser();
4262+
}
4263+
const functionSignature = fnData.functionSignature;
4264+
if (!unifyFunctionTypes(
4265+
functionSignature.inputs,
4266+
inputs,
4267+
functionSignature.where_clause,
4268+
null,
4269+
mgens => {
4270+
return !!unifyFunctionTypes(
4271+
functionSignature.output,
4272+
output,
4273+
functionSignature.where_clause,
4274+
mgens,
4275+
checkTypeMgensForConflict,
4276+
0, // unboxing depth
4277+
);
4278+
},
4279+
0, // unboxing depth
4280+
)) {
4281+
return null;
4282+
}
4283+
return {
4284+
id,
4285+
dist: fnData.elemCount,
4286+
path_dist: 0,
4287+
index: -1,
4288+
elems: inputs,
4289+
returned: output,
4290+
is_alias: false,
4291+
};
4292+
}));
42864293
}
42874294
}
42884295
}
42894296
yield* sortAndTransformResults(
4290-
results,
4297+
await Promise.all(resultPromises),
42914298
typeInfo,
42924299
currentCrate,
42934300
new Set(),
-1.81 MB
Binary file not shown.
-14.1 KB
Binary file not shown.

0 commit comments

Comments
 (0)