Skip to content

Commit

Permalink
Rollup merge of #108494 - GuillaumeGomez:cleanup-js, r=notriddle
Browse files Browse the repository at this point in the history
Clean up JS files code a bit

I mostly moved values closer to where they are used to make the code reading easier.

r? ``@notriddle``
  • Loading branch information
compiler-errors authored Feb 26, 2023
2 parents 7ebd3dd + 27db688 commit 393ef7d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 13 deletions.
17 changes: 6 additions & 11 deletions src/librustdoc/html/static/js/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -463,11 +463,10 @@ function initSearch(rawSearchIndex) {
* @param {ParserState} parserState
*/
function parseInput(query, parserState) {
let c, before;
let foundStopChar = true;

while (parserState.pos < parserState.length) {
c = parserState.userQuery[parserState.pos];
const c = parserState.userQuery[parserState.pos];
if (isStopCharacter(c)) {
foundStopChar = true;
if (isSeparatorCharacter(c)) {
Expand Down Expand Up @@ -506,7 +505,7 @@ function initSearch(rawSearchIndex) {
}
throw new Error(`Expected \`,\`, \` \`, \`:\` or \`->\`, found \`${c}\``);
}
before = query.elems.length;
const before = query.elems.length;
getNextElem(query, parserState, query.elems, false);
if (query.elems.length === before) {
// Nothing was added, weird... Let's increase the position to not remain stuck.
Expand All @@ -515,7 +514,6 @@ function initSearch(rawSearchIndex) {
foundStopChar = false;
}
while (parserState.pos < parserState.length) {
c = parserState.userQuery[parserState.pos];
if (isReturnArrow(parserState)) {
parserState.pos += 2;
// Get returned elements.
Expand Down Expand Up @@ -1940,7 +1938,6 @@ function initSearch(rawSearchIndex) {
*/
const searchWords = [];
const charA = "A".charCodeAt(0);
let i, word;
let currentIndex = 0;
let id = 0;

Expand Down Expand Up @@ -2035,7 +2032,7 @@ function initSearch(rawSearchIndex) {
// convert `rawPaths` entries into object form
// generate normalizedPaths for function search mode
let len = paths.length;
for (i = 0; i < len; ++i) {
for (let i = 0; i < len; ++i) {
lowercasePaths.push({ty: paths[i][0], name: paths[i][1].toLowerCase()});
paths[i] = {ty: paths[i][0], name: paths[i][1]};
}
Expand All @@ -2049,16 +2046,14 @@ function initSearch(rawSearchIndex) {
// faster analysis operations
len = itemTypes.length;
let lastPath = "";
for (i = 0; i < len; ++i) {
for (let i = 0; i < len; ++i) {
let word = "";
// This object should have exactly the same set of fields as the "crateRow"
// object defined above.
if (typeof itemNames[i] === "string") {
word = itemNames[i].toLowerCase();
searchWords.push(word);
} else {
word = "";
searchWords.push("");
}
searchWords.push(word);
const row = {
crate: crate,
ty: itemTypes.charCodeAt(i) - charA,
Expand Down
3 changes: 1 addition & 2 deletions src/librustdoc/html/static/js/source-script.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,7 @@ function createSourceSidebar() {
sidebar.appendChild(title);
Object.keys(sourcesIndex).forEach(key => {
sourcesIndex[key][NAME_OFFSET] = key;
hasFoundFile = createDirEntry(sourcesIndex[key], sidebar, "",
hasFoundFile);
hasFoundFile = createDirEntry(sourcesIndex[key], sidebar, "", hasFoundFile);
});

container.appendChild(sidebar);
Expand Down

0 comments on commit 393ef7d

Please sign in to comment.