From ce5cfd228a2fece13fe7aeabaa8297d976f31e37 Mon Sep 17 00:00:00 2001 From: Jentsch Date: Wed, 23 Oct 2013 12:59:45 +0200 Subject: Prevent useless filter operation in docs --- .../scala/tools/nsc/doc/html/resource/lib/index.js | 71 ++++++++++++---------- 1 file changed, 38 insertions(+), 33 deletions(-) (limited to 'src') diff --git a/src/scaladoc/scala/tools/nsc/doc/html/resource/lib/index.js b/src/scaladoc/scala/tools/nsc/doc/html/resource/lib/index.js index 96689ae701..c201b324e7 100644 --- a/src/scaladoc/scala/tools/nsc/doc/html/resource/lib/index.js +++ b/src/scaladoc/scala/tools/nsc/doc/html/resource/lib/index.js @@ -383,51 +383,56 @@ function compilePattern(query) { // Filters all focused templates and packages. This function should be made less-blocking. // @param query The string of the query function textFilter() { - scheduler.clear("filter"); - - $('#tpl').html(''); - var query = $("#textfilter input").attr("value") || ''; var queryRegExp = compilePattern(query); - var index = 0; + if ((typeof textFilter.lastQuery === "undefined") || (textFilter.lastQuery !== query)) { + + textFilter.lastQuery = query; - var searchLoop = function () { - var packages = Index.keys(Index.PACKAGES).sort(); + scheduler.clear("filter"); - while (packages[index]) { - var pack = packages[index]; - var children = Index.PACKAGES[pack]; - index++; + $('#tpl').html(''); - if (focusFilterState) { - if (pack == focusFilterState || - pack.indexOf(focusFilterState + '.') == 0) { - ; - } else { - continue; + var index = 0; + + var searchLoop = function () { + var packages = Index.keys(Index.PACKAGES).sort(); + + while (packages[index]) { + var pack = packages[index]; + var children = Index.PACKAGES[pack]; + index++; + + if (focusFilterState) { + if (pack == focusFilterState || + pack.indexOf(focusFilterState + '.') == 0) { + ; + } else { + continue; + } } - } - var matched = $.grep(children, function (child, i) { - return queryRegExp.test(child.name); - }); + var matched = $.grep(children, function (child, i) { + return queryRegExp.test(child.name); + }); - if (matched.length > 0) { - $('#tpl').append(Index.createPackageTree(pack, matched, - focusFilterState)); - scheduler.add('filter', searchLoop); - return; + if (matched.length > 0) { + $('#tpl').append(Index.createPackageTree(pack, matched, + focusFilterState)); + scheduler.add('filter', searchLoop); + return; + } } - } - $('#tpl a.packfocus').click(function () { - focusFilter($(this).parent().parent()); - }); - configureHideFilter(); - }; + $('#tpl a.packfocus').click(function () { + focusFilter($(this).parent().parent()); + }); + configureHideFilter(); + }; - scheduler.add('filter', searchLoop); + scheduler.add('filter', searchLoop); + } } /* Configures the hide tool by adding the hide link to all packages. */ -- cgit v1.2.3