From e446a87f1bbbf7763518b5736a9d3f18c451e324 Mon Sep 17 00:00:00 2001 From: Kang Seonghoon Date: Wed, 9 Apr 2014 02:45:53 +0900 Subject: [PATCH 1/3] mk: Add a dummy CFG_COMPILER_HOST_TRIPLE to rustdoc invocation. Otherwise it will prohibit `make compiler-docs` on Windows. --- mk/docs.mk | 1 + 1 file changed, 1 insertion(+) diff --git a/mk/docs.mk b/mk/docs.mk index fab828571cd4f..ddc3b175d1015 100644 --- a/mk/docs.mk +++ b/mk/docs.mk @@ -269,6 +269,7 @@ LIB_DOC_DEP_$(1) = $$(CRATEFILE_$(1)) $$(RSINPUTS_$(1)) endif $(2) += doc/$(1)/index.html +doc/$(1)/index.html: CFG_COMPILER_HOST_TRIPLE = $(CFG_TARGET) doc/$(1)/index.html: $$(LIB_DOC_DEP_$(1)) @$$(call E, rustdoc $$@) $$(Q)$$(RUSTDOC) --cfg dox --cfg stage2 $$< From 17f94d037ce5a6fe06071cf9fe384e73cabd78a5 Mon Sep 17 00:00:00 2001 From: Kang Seonghoon Date: Wed, 9 Apr 2014 02:47:52 +0900 Subject: [PATCH 2/3] rustdoc: Clean the `initSearch` routine up. --- src/librustdoc/html/static/main.js | 82 ++++++++++++++---------------- 1 file changed, 39 insertions(+), 43 deletions(-) diff --git a/src/librustdoc/html/static/main.js b/src/librustdoc/html/static/main.js index ffdf67e56cf7f..1904ab27d17d9 100644 --- a/src/librustdoc/html/static/main.js +++ b/src/librustdoc/html/static/main.js @@ -137,8 +137,6 @@ val = valLower, typeFilter = query.type, results = [], - aa = 0, - bb = 0, split = valLower.split("::"); //remove empty keywords @@ -150,16 +148,16 @@ } // quoted values mean literal search - bb = searchWords.length; + var nSearchWords = searchWords.length; if ((val.charAt(0) === "\"" || val.charAt(0) === "'") && val.charAt(val.length - 1) === val.charAt(0)) { val = val.substr(1, val.length - 2); - for (aa = 0; aa < bb; aa += 1) { - if (searchWords[aa] === val) { + for (var i = 0; i < nSearchWords; i += 1) { + if (searchWords[i] === val) { // filter type: ... queries - if (!typeFilter || typeFilter === searchIndex[aa].ty) { - results.push([aa, -1]); + if (!typeFilter || typeFilter === searchIndex[i].ty) { + results.push({id: i, index: -1}); } } if (results.length === max) { @@ -170,14 +168,14 @@ // gather matching search results up to a certain maximum val = val.replace(/\_/g, ""); for (var i = 0; i < split.length; i++) { - for (aa = 0; aa < bb; aa += 1) { - if (searchWords[aa].indexOf(split[i]) > -1 || - searchWords[aa].indexOf(val) > -1 || - searchWords[aa].replace(/_/g, "").indexOf(val) > -1) + for (var j = 0; j < nSearchWords; j += 1) { + if (searchWords[j].indexOf(split[i]) > -1 || + searchWords[j].indexOf(val) > -1 || + searchWords[j].replace(/_/g, "").indexOf(val) > -1) { // filter type: ... queries - if (!typeFilter || typeFilter === searchIndex[aa].ty) { - results.push([aa, searchWords[aa].replace(/_/g, "").indexOf(val)]); + if (!typeFilter || typeFilter === searchIndex[j].ty) { + results.push({id: j, index: searchWords[j].replace(/_/g, "").indexOf(val)}); } } if (results.length === max) { @@ -187,13 +185,12 @@ } } - bb = results.length; - for (aa = 0; aa < bb; aa += 1) { - results[aa].push(searchIndex[results[aa][0]].ty); - results[aa].push(searchIndex[results[aa][0]].path); - results[aa].push(searchIndex[results[aa][0]].name); - results[aa].push(searchIndex[results[aa][0]].parent); - results[aa].push(searchIndex[results[aa][0]].crate); + var nresults = results.length; + for (var i = 0; i < nresults; i += 1) { + results[i].word = searchWords[results[i].id]; + results[i].item = searchIndex[results[i].id] || {}; + results[i].ty = results[i].item.ty; + results[i].path = results[i].item.path; } // if there are no results then return to default and fail if (results.length === 0) { @@ -202,31 +199,31 @@ // sort by exact match results.sort(function search_complete_sort0(aaa, bbb) { - if (searchWords[aaa[0]] === valLower && - searchWords[bbb[0]] !== valLower) { + if (aaa.word === valLower && + bbb.word !== valLower) { return 1; } }); // first sorting attempt // sort by item name length results.sort(function search_complete_sort1(aaa, bbb) { - if (searchWords[aaa[0]].length > searchWords[bbb[0]].length) { + if (aaa.word.length > bbb.word.length) { return 1; } }); // second sorting attempt // sort by item name results.sort(function search_complete_sort1(aaa, bbb) { - if (searchWords[aaa[0]].length === searchWords[bbb[0]].length && - searchWords[aaa[0]] > searchWords[bbb[0]]) { + if (aaa.word.length === bbb.word.length && + aaa.word > bbb.word) { return 1; } }); // third sorting attempt // sort by index of keyword in item name - if (results[0][1] !== -1) { + if (results[0].index !== -1) { results.sort(function search_complete_sort1(aaa, bbb) { - if (aaa[1] > bbb[1] && bbb[1] === 0) { + if (aaa.index > bbb.index && bbb.index === 0) { return 1; } }); @@ -234,38 +231,38 @@ // fourth sorting attempt // sort by type results.sort(function search_complete_sort3(aaa, bbb) { - if (searchWords[aaa[0]] === searchWords[bbb[0]] && - aaa[2] > bbb[2]) { + if (aaa.word === bbb.word && + aaa.ty > bbb.ty) { return 1; } }); // fifth sorting attempt // sort by path results.sort(function search_complete_sort4(aaa, bbb) { - if (searchWords[aaa[0]] === searchWords[bbb[0]] && - aaa[2] === bbb[2] && aaa[3] > bbb[3]) { + if (aaa.word === bbb.word && + aaa.ty === bbb.ty && aaa.path > bbb.path) { return 1; } }); // sixth sorting attempt // remove duplicates, according to the data provided - for (aa = results.length - 1; aa > 0; aa -= 1) { - if (searchWords[results[aa][0]] === searchWords[results[aa - 1][0]] && - results[aa][2] === results[aa - 1][2] && - results[aa][3] === results[aa - 1][3]) + for (var i = results.length - 1; i > 0; i -= 1) { + if (results[i].word === results[i - 1].word && + results[i].ty === results[i - 1].ty && + results[i].path === results[i - 1].path) { - results[aa][0] = -1; + results[i].id = -1; } } for (var i = 0; i < results.length; i++) { var result = results[i], - name = result[4].toLowerCase(), - path = result[3].toLowerCase(), - parent = allPaths[result[6]][result[5]]; + name = result.item.name.toLowerCase(), + path = result.item.path.toLowerCase(), + parent = allPaths[result.item.crate][result.item.parent]; var valid = validateResult(name, path, split, parent); if (!valid) { - result[0] = -1; + result.id = -1; } } return results; @@ -495,8 +492,8 @@ resultIndex = execQuery(query, 20000, index); len = resultIndex.length; for (i = 0; i < len; i += 1) { - if (resultIndex[i][0] > -1) { - obj = searchIndex[resultIndex[i][0]]; + if (resultIndex[i].id > -1) { + obj = searchIndex[resultIndex[i].id]; filterdata.push([obj.name, obj.ty, obj.path, obj.desc]); results.push(obj); } @@ -580,7 +577,6 @@ // Draw a convenient sidebar of known crates if we have a listing if (rootPath == '../') { - console.log('here'); var sidebar = $('.sidebar'); var div = $('
').attr('class', 'block crate'); div.append($('

').text('Crates')); From b9e1f6e2679748fc48dad8de8d0335b52fffcdfe Mon Sep 17 00:00:00 2001 From: Kang Seonghoon Date: Wed, 9 Apr 2014 03:25:54 +0900 Subject: [PATCH 3/3] rustdoc: Prune the paths that do not appear in the index. For the full library and compiler docs, the size of `search-index.js` decreases by 13% (18.5% after gzip -9) which is a substantial gain. --- src/librustdoc/html/render.rs | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs index 3ed4ece514ad0..035e4c623755a 100644 --- a/src/librustdoc/html/render.rs +++ b/src/librustdoc/html/render.rs @@ -262,10 +262,11 @@ pub fn run(mut krate: clean::Crate, dst: Path) -> io::IoResult<()> { cache.stack.push(krate.name.clone()); krate = cache.fold_crate(krate); { + let Cache { search_index: ref mut index, + orphan_methods: ref meths, paths: ref mut paths, ..} = cache; + // Attach all orphan methods to the type's definition if the type // has since been learned. - let Cache { search_index: ref mut index, - orphan_methods: ref meths, paths: ref paths, ..} = cache; for &(ref pid, ref item) in meths.iter() { match paths.find(pid) { Some(&(ref fqp, _)) => { @@ -280,6 +281,18 @@ pub fn run(mut krate: clean::Crate, dst: Path) -> io::IoResult<()> { None => {} } }; + + // Prune the paths that do not appear in the index. + let mut unseen: HashSet = paths.keys().map(|&id| id).collect(); + for item in index.iter() { + match item.parent { + Some(ref pid) => { unseen.remove(pid); } + None => {} + } + } + for pid in unseen.iter() { + paths.remove(pid); + } } // Publish the search index