diff options
| author | Guillaume Gomez <guillaume1.gomez@gmail.com> | 2020-12-30 16:36:08 +0100 |
|---|---|---|
| committer | Guillaume Gomez <guillaume1.gomez@gmail.com> | 2021-01-15 22:52:33 +0100 |
| commit | 7cd8128da3d81bdc8f6e9da19f09f236c1703800 (patch) | |
| tree | 3329b88669766522ea49b0702c2155aa455b3feb /src/librustdoc/html/static/source-script.js | |
| parent | 887398ff688e2e3cf8a95e588d0b51420e08fb6b (diff) | |
| download | rust-7cd8128da3d81bdc8f6e9da19f09f236c1703800.tar.gz rust-7cd8128da3d81bdc8f6e9da19f09f236c1703800.zip | |
Improve JS performance by storing length before comparing to it in loops
Diffstat (limited to 'src/librustdoc/html/static/source-script.js')
| -rw-r--r-- | src/librustdoc/html/static/source-script.js | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/src/librustdoc/html/static/source-script.js b/src/librustdoc/html/static/source-script.js index 6805f2a266f..a9cc0ffdf79 100644 --- a/src/librustdoc/html/static/source-script.js +++ b/src/librustdoc/html/static/source-script.js @@ -8,7 +8,7 @@ function getCurrentFilePath() { var parts = window.location.pathname.split("/"); var rootPathParts = window.rootPath.split("/"); - for (var i = 0; i < rootPathParts.length; ++i) { + for (var i = 0, len = rootPathParts.length; i < len; ++i) { if (rootPathParts[i] === "..") { parts.pop(); } @@ -35,12 +35,14 @@ function createDirEntry(elem, parent, fullPath, currentFile, hasFoundFile) { }; name.innerText = elem["name"]; + var i, len; + var children = document.createElement("div"); children.className = "children"; var folders = document.createElement("div"); folders.className = "folders"; if (elem.dirs) { - for (var i = 0; i < elem.dirs.length; ++i) { + for (i = 0, len = elem.dirs.length; i < len; ++i) { if (createDirEntry(elem.dirs[i], folders, fullPath, currentFile, hasFoundFile) === true) { addClass(name, "expand"); @@ -53,7 +55,7 @@ function createDirEntry(elem, parent, fullPath, currentFile, hasFoundFile) { var files = document.createElement("div"); files.className = "files"; if (elem.files) { - for (i = 0; i < elem.files.length; ++i) { + for (i = 0, len = elem.files.length; i < len; ++i) { var file = document.createElement("a"); file.innerText = elem.files[i]; file.href = window.rootPath + "src/" + fullPath + elem.files[i] + ".html"; |
