Skip to content

Rollup of 10 pull requests #83199

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 36 commits into from
Mar 16, 2021
Merged
Changes from 1 commit
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
66f7f7d
Added `try_exists()` method to `std::path::Path`
Kixunil Feb 6, 2021
81d1d82
Update `Vec` docs
henrytheswimmer Mar 13, 2021
5fe3b87
Get rid of the garbage produced by getObjectFromId
notriddle Mar 13, 2021
d7971e5
In checkGenerics and checkType, don't use Array.prototype.splice so much
notriddle Mar 13, 2021
3f70bfa
Eagerly generate the underscore-less name to search on
notriddle Mar 13, 2021
b76a3d3
Update src/librustdoc/html/static/main.js
notriddle Mar 13, 2021
ca04ce3
Use null instead of undefined here
notriddle Mar 13, 2021
b7d14b1
Fix jslint warnings
notriddle Mar 13, 2021
7834aeb
Add comments regarding object shapes in buildIndex
notriddle Mar 13, 2021
26f85cc
Avoid potential collisions with `constructor` and the search query
notriddle Mar 13, 2021
d92f840
Remove tab character
notriddle Mar 13, 2021
0bfd142
Avoid generating new strings for names that have no undescores
notriddle Mar 14, 2021
f57d715
Use a number for row.id, instead of a string
notriddle Mar 14, 2021
8eba927
Make nameWithoutUndescores lowercased
notriddle Mar 14, 2021
7134b0e
Fall-back to sans-serif if Arial is not available
nagisa Mar 15, 2021
9aa48ba
No background for code in portability snippets
nagisa Mar 15, 2021
dcba95f
Declare `word` outside the loop, as recommended by eslint
notriddle Mar 15, 2021
ff8717b
Specify *.woff2 files as binary
jfrimmel Mar 15, 2021
924e522
Deprecate RustcEncodable and RustcDecodable.
m-ou-se Mar 15, 2021
62cf244
Constify copy_to and copy_from
usbalbin Mar 13, 2021
64e2248
Constify mem::swap and ptr::swap[_nonoverlapping]
usbalbin Mar 13, 2021
45988ee
Constify mem::replace and ptr::replace
usbalbin Mar 13, 2021
db9a53b
Constify mem::transmute_copy
usbalbin Mar 13, 2021
335427a
Use delay_span_bug instead of panic in layout_scalar_valid_range
tmiasko Mar 16, 2021
d6de60f
Make bootstrap be more informative when one does `x.py test` on a bet…
pnkfelix Mar 15, 2021
4330268
Filled tracking issue for path_try_exists
Kixunil Mar 16, 2021
62d38da
Rollup merge of #81822 - Kixunil:path_try_exists, r=kennytm
JohnTitor Mar 16, 2021
b6df781
Rollup merge of #83072 - henryboisdequin:patch-1, r=Dylan-DPC
JohnTitor Mar 16, 2021
dbdb2a1
Rollup merge of #83077 - notriddle:gc-cleanup-rustdoc-search, r=Guill…
JohnTitor Mar 16, 2021
d3460cd
Rollup merge of #83091 - usbalbin:const_copy, r=oli-obk
JohnTitor Mar 16, 2021
0f6b206
Rollup merge of #83156 - nagisa:nagisa/sans-serif-please, r=Guillaume…
JohnTitor Mar 16, 2021
896b44a
Rollup merge of #83157 - nagisa:nagisa/portability-background, r=Guil…
JohnTitor Mar 16, 2021
39af66f
Rollup merge of #83160 - m-ou-se:deprecate-rustc-serialize-derives, r…
JohnTitor Mar 16, 2021
70bacd6
Rollup merge of #83162 - jfrimmel:woff2, r=Mark-Simulacrum
JohnTitor Mar 16, 2021
b62997f
Rollup merge of #83172 - pnkfelix:bootstrap-tell-me-what-to-do-about-…
JohnTitor Mar 16, 2021
ec07427
Rollup merge of #83196 - tmiasko:valid-range-delay-span-bug, r=oli-obk
JohnTitor Mar 16, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
In checkGenerics and checkType, don't use Array.prototype.splice so much
Every time splice() is called, another temporary object is created.
This version, which uses plain objects as a sort of Hash Bag,
should only produce one temporary object each time it's called.
  • Loading branch information
notriddle committed Mar 13, 2021
commit d7971e587c948ce943d962073ea3caa7f6830c1d
94 changes: 57 additions & 37 deletions src/librustdoc/html/static/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -846,26 +846,38 @@ function defocusSearchBar() {
if (val.generics.length > 0) {
if (obj.length > GENERICS_DATA &&
obj[GENERICS_DATA].length >= val.generics.length) {
var elems = obj[GENERICS_DATA].slice(0);
var elems = {};
var elength = object[GENERICS_DATA].length;
for (var x = 0; x < elength; ++x) {
elems[getObjectNameFromId(obj[GENERICS_DATA][x])] += 1;
}
var total = 0;
var done = 0;
// We need to find the type that matches the most to remove it in order
// to move forward.
var vlength = val.generics.length;
for (var y = 0; y < vlength; ++y) {
var lev = { pos: -1, lev: MAX_LEV_DISTANCE + 1};
var firstGeneric = getObjectNameFromId(val.generics[y]);
for (var x = 0, elength = elems.length; x < elength; ++x) {
var tmp_lev = levenshtein(getObjectNameFromId(elems[x]),
firstGeneric);
if (tmp_lev < lev.lev) {
lev.lev = tmp_lev;
lev.pos = x;
for (var x = 0; x < vlength; ++x) {
var lev = MAX_LEV_DISTANCE + 1;
var firstGeneric = getObjectNameFromId(val.generics[x]);
var match = undefined;
if (elems[firstGeneric]) {
match = firstGeneric;
lev = 0;
} else {
for (var elem_name in elems) {
var tmp_lev = levenshtein(elem_name, firstGeneric);
if (tmp_lev < lev) {
lev = tmp_lev;
match = elem_name;
}
}
}
if (lev.pos !== -1) {
elems.splice(lev.pos, 1);
total += lev.lev;
if (match !== undefined) {
elems[match] -= 1;
if (elems[match] == 0) {
delete elems[match];
}
total += lev;
done += 1;
} else {
return MAX_LEV_DISTANCE + 1;
Expand All @@ -880,25 +892,27 @@ function defocusSearchBar() {
// Check for type name and type generics (if any).
function checkType(obj, val, literalSearch) {
var lev_distance = MAX_LEV_DISTANCE + 1;
var len, x, y, e_len, firstGeneric;
var len, x, firstGeneric;
if (obj[NAME] === val.name) {
if (literalSearch === true) {
if (val.generics && val.generics.length !== 0) {
if (obj.length > GENERICS_DATA &&
obj[GENERICS_DATA].length >= val.generics.length) {
var elems = obj[GENERICS_DATA].slice(0);
var allFound = true;
var elems = {};
len = obj[GENERICS_DATA].length;
for (x = 0; x < len; ++x) {
elems[getObjectNameFromId(obj[GENERICS_DATA][x])] += 1;
}

var allFound = true;
len = val.generics.length;
for (y = 0; allFound === true && y < len; ++y) {
allFound = false;
firstGeneric = getObjectNameFromId(val.generics[y]);
e_len = elems.length;
for (x = 0; allFound === false && x < e_len; ++x) {
allFound = getObjectNameFromId(elems[x]) === firstGeneric;
}
if (allFound === true) {
elems.splice(x - 1, 1);
for (x = 0; x < len; ++x) {
firstGeneric = getObjectNameFromId(val.generics[x]);
if (elems[firstGeneric]) {
elems[firstGeneric] -= 1;
} else {
allFound = false;
break;
}
}
if (allFound === true) {
Expand Down Expand Up @@ -1066,13 +1080,6 @@ function defocusSearchBar() {
return false;
}

function generateId(ty) {
if (ty.parent && ty.parent.name) {
return itemTypes[ty.ty] + ty.path + ty.parent.name + ty.name;
}
return itemTypes[ty.ty] + ty.path + ty.name;
}

function createAliasFromItem(item) {
return {
crate: item.crate,
Expand Down Expand Up @@ -1158,7 +1165,7 @@ function defocusSearchBar() {
in_args = findArg(searchIndex[i], val, true, typeFilter);
returned = checkReturned(searchIndex[i], val, true, typeFilter);
ty = searchIndex[i];
fullId = generateId(ty);
fullId = ty.id;

if (searchWords[i] === val.name
&& typePassesFilter(typeFilter, searchIndex[i].ty)
Expand Down Expand Up @@ -1208,7 +1215,7 @@ function defocusSearchBar() {
if (!type) {
continue;
}
fullId = generateId(ty);
fullId = ty.id;

returned = checkReturned(ty, output, true, NO_TYPE_FILTER);
if (output.name === "*" || returned === true) {
Expand Down Expand Up @@ -1292,7 +1299,7 @@ function defocusSearchBar() {
var index = -1;
// we want lev results to go lower than others
lev = MAX_LEV_DISTANCE + 1;
fullId = generateId(ty);
fullId = ty.id;

if (searchWords[j].indexOf(split[i]) > -1 ||
searchWords[j].indexOf(val) > -1 ||
Expand Down Expand Up @@ -1825,6 +1832,13 @@ function defocusSearchBar() {
showResults(execSearch(query, index, filterCrates));
}

function generateId(ty) {
if (ty.parent && ty.parent.name) {
return itemTypes[ty.ty] + ty.path + ty.parent.name + ty.name;
}
return itemTypes[ty.ty] + ty.path + ty.name;
}

function buildIndex(rawSearchIndex) {
searchIndex = [];
var searchWords = [];
Expand All @@ -1837,14 +1851,18 @@ function defocusSearchBar() {
var crateSize = 0;

searchWords.push(crate);
searchIndex.push({
var crateRow = {
crate: crate,
ty: 1, // == ExternCrate
name: crate,
path: "",
desc: rawSearchIndex[crate].doc,
parent: undefined,
type: null,
});
id: "",
};
crateRow.id = generateId(crateRow);
searchIndex.push(crateRow);
currentIndex += 1;

// an array of (Number) item types
Expand Down Expand Up @@ -1890,7 +1908,9 @@ function defocusSearchBar() {
desc: itemDescs[i],
parent: itemParentIdxs[i] > 0 ? paths[itemParentIdxs[i] - 1] : undefined,
type: itemFunctionSearchTypes[i],
id: "",
};
row.id = generateId(row);
searchIndex.push(row);
if (typeof row.name === "string") {
var word = row.name.toLowerCase();
Expand Down