Skip to content

Commit

Permalink
rustdoc: Separate filter-empty-string out into its own function
Browse files Browse the repository at this point in the history
  • Loading branch information
notriddle committed Apr 1, 2021
1 parent 6530b32 commit 227f5ed
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
13 changes: 11 additions & 2 deletions src/librustdoc/html/static/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,15 @@ function hideThemeButtonState() {
var titleBeforeSearch = document.title;
var searchTitle = null;

function removeEmptyStringsFromArray(x) {
for (var i = 0, len = x.length; i < len; ++i) {
if (x[i] === "") {
x.splice(i, 1);
i -= 1;
}
}
}

function clearInputTimeout() {
if (searchTimeout !== null) {
clearTimeout(searchTimeout);
Expand Down Expand Up @@ -756,7 +765,7 @@ function hideThemeButtonState() {
results = {}, results_in_args = {}, results_returned = {},
split = valLower.split("::");

split = split.filter(function(segment) { return segment !== ""; });
removeEmptyStringsFromArray(split);

function transformResults(results, isType) {
var out = [];
Expand Down Expand Up @@ -1338,7 +1347,7 @@ function hideThemeButtonState() {
var valGenerics = extractGenerics(val);

var paths = valLower.split("::");
paths = paths.filter(function(segment) { return segment !== ""; });
removeEmptyStringsFromArray(paths);
val = paths[paths.length - 1];
var contains = paths.slice(0, paths.length > 1 ? paths.length - 1 : 1);

Expand Down
3 changes: 2 additions & 1 deletion src/tools/rustdoc-js/tester.js
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,8 @@ function loadMainJsAndIndex(mainJs, searchIndex, storageJs, crate) {
// execQuery last parameter is built in buildIndex.
// buildIndex requires the hashmap from search-index.
var functionsToLoad = ["buildHrefAndPath", "pathSplitter", "levenshtein", "validateResult",
"handleAliases", "getQuery", "buildIndex", "execQuery", "execSearch"];
"handleAliases", "getQuery", "buildIndex", "execQuery", "execSearch",
"removeEmptyStringsFromArray"];

ALIASES = {};
finalJS += 'window = { "currentCrate": "' + crate + '", rootPath: "../" };\n';
Expand Down

0 comments on commit 227f5ed

Please sign in to comment.