Improve JS performance by storing length before comparing to it in loops
This commit is contained in:
parent
887398ff68
commit
7cd8128da3
2 changed files with 50 additions and 56 deletions
|
|
@ -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";
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue