about summary refs log tree commit diff
path: root/src/librustdoc/html/static/main.js
AgeCommit message (Collapse)AuthorLines
2021-03-23Rollup merge of #82732 - GuillaumeGomez:remove-theme-file, r=Nemo157Yuki Okushi-8/+69
Remove theme.js file Fixes #82616. The first commit moves the `theme.js` file into `main.js`, which requires to also run a small `.replace` on the `main.js` content. The second commit is just a small cleanup to centralize DOM ids. Since it removes a file from rustdoc output: cc `@rust-lang/docs-rs` cc `@jsha` r? `@jyn514`
2021-03-19Ignore main.js file lengthGuillaume Gomez-0/+1
2021-03-19Only build help popup when it's really neededGuillaume Gomez-12/+19
2021-03-16Rollup merge of #83077 - notriddle:gc-cleanup-rustdoc-search, r=GuillaumeGomezYuki Okushi-49/+78
rustdoc: reduce GC work during search
2021-03-15Declare `word` outside the loop, as recommended by eslintMichael Howell-3/+3
2021-03-14Make nameWithoutUndescores lowercasedMichael Howell-14/+15
This basically fixes a search bug introduced by earlier changes.
2021-03-14Use a number for row.id, instead of a stringMichael Howell-11/+5
There's no reason for it to be a string, since it's only used for de-duplicating the results arrays anyhow.
2021-03-14Avoid generating new strings for names that have no undescoresMichael Howell-2/+8
This should have negligible effect on time, but it cuts about 1MiB off of resident memory usage.
2021-03-14Auto merge of #83028 - GuillaumeGomez:prevent-js-error-if-no-filter, r=Nemo157bors-1/+5
Prevent JS error when there is no dependency or other crate documented (or --disable-per-crate-search has been used) When there is only one crate, the dropdown is removed, creating an error (that you can see pretty easily on docs.rs for example). r? `@jyn514`
2021-03-13Remove tab characterMichael Howell-2/+2
2021-03-13Avoid potential collisions with `constructor` and the search queryMichael Howell-2/+2
2021-03-13Add comments regarding object shapes in buildIndexMichael Howell-0/+5
2021-03-13Fix jslint warningsMichael Howell-2/+3
2021-03-13Use null instead of undefined hereMichael Howell-2/+2
2021-03-13Update src/librustdoc/html/static/main.jsMichael Howell-1/+1
Co-authored-by: Guillaume Gomez <guillaume1.gomez@gmail.com>
2021-03-13Eagerly generate the underscore-less name to search onMichael Howell-2/+4
Basically, it doesn't make sense to generate those things every time you search. That generates a bunch of stuff for the GC to clean up, when, if the user wanted to do another search, it would just need to re-do it again.
2021-03-13In checkGenerics and checkType, don't use Array.prototype.splice so muchMichael Howell-37/+57
Every time splice() is called, another temporary object is created. This version, which uses plain objects as a sort of Hash Bag, should only produce one temporary object each time it's called.
2021-03-12Get rid of the garbage produced by getObjectFromIdMichael Howell-7/+7
There is no reason for this function to return an object, since it is always used for getting at the name anyhow. It's used in the inner loop for some popular functions, so we want to avoid allocating in it.
2021-03-11Prevent JS error when there is no dependency or other crate documentedGuillaume Gomez-1/+5
2021-03-10rustdoc: tweak the search index formatMichael Howell-19/+20
This essentially switches search-index.js from a "array of struct" to a "struct of array" format, like this: { "doc": "Crate documentation", "t": [ 1, 1, 2, 3, ... ], "n": [ "Something", "SomethingElse", "whatever", "do_stuff", ... ], "q": [ "a::b", "", "", "", ... ], "d": [ "A Struct That Does Something", "Another Struct", "a function", "another function", ... ], "i": [ 0, 0, 1, 1, ... ], "f": [ null, null, [], [], ... ], "p": ..., "a": ... } So `{ty: 1, name: "Something", path: "a::b", desc: "A Struct That Does Something", parent_idx: 0, search_type: null}` is the first item. This makes the uncompressed version smaller, but it really shows on the compressed version: notriddle:rust$ wc -c new-search-index1.52.0.js 2622427 new-search-index1.52.0.js notriddle:rust$ wc -c old-search-index1.52.0.js 2725046 old-search-index1.52.0.js notriddle:rust$ gzip new-search-index1.52.0.js notriddle:rust$ gzip old-search-index1.52.0.js notriddle:rust$ wc -c new-search-index1.52.0.js.gz 239385 new-search-index1.52.0.js.gz notriddle:rust$ wc -c old-search-index1.52.0.js.gz 296328 old-search-index1.52.0.js.gz notriddle:rust$ That's a 4% improvement on the uncompressed version (fewer `[]`), and 20% improvement after gzipping it, thanks to putting like-typed data next to each other. Any compression algorithm based on a sliding window will probably show this kind of improvement.
2021-03-10Rollup merge of #82807 - notriddle:cleanup-js, r=jyn514Dylan DPC-10/+2
rustdoc: Remove redundant enableSearchInput function enableSearchInput was called from two places: - setupSearchLoader - addSearchOptions, which is itself called from setupSearchLoader only This commit can safely get rid of the addSearchOptions calls entirely, and since the setupSearchLoader call is immediately preceded by other method calls on search_input, there's no need to check if it's set.
2021-03-05Use substrings instead of split to grab enum variant pathsMichael Howell-3/+3
Both versions are about equally readable, but this version avoids scanning the entire path and building an intermediate array (`split()` in Rust is a lazy iterator, but not in JavaScript).
2021-03-05Remove redundant enableSearchInput functionMichael Howell-10/+2
enableSearchInput was called from two places: - setupSearchLoader - addSearchOptions, which is itself called from setupSearchLoader only This commit can safely get rid of the addSearchOptions calls entirely, and since the setupSearchLoader call is immediately preceded by other method calls on search_input, there's no need to check if it's set.
2021-03-05Use global variables instead of functions for DOM IDsGuillaume Gomez-16/+11
2021-03-05Clean up code around theme elementsGuillaume Gomez-11/+19
2021-03-05Remove theme.js file creation and move its code inside main.jsGuillaume Gomez-1/+60
2021-03-04Remove unused code from main.jsMichael Howell-20/+0
It looks like `lev_distance` was used in a very old version of the function, since it was written but never read, and Blame reports that it was added before the `checkGenerics` function header itself. `convertHTMLToPlaintext` is was removed by 768d5e950953738a54480e530341964838d29da2
2021-03-02Load rustdoc's JS search index on-demand.Jacob Hoffman-Andrews-42/+56
Instead of being loaded on every page, the JS search index is now loaded when either (a) there is a `?search=` param, or (b) the search input is focused. This saves both CPU and bandwidth. As of Feb 2021, https://doc.rust-lang.org/search-index1.50.0.js is 273,838 bytes gzipped or 2,544,939 bytes uncompressed. Evaluating it takes 445 ms of CPU time in Chrome 88 on a i7-10710U CPU (out of a total ~2,100 ms page reload). Generate separate JS file with crate names. This is much smaller than the full search index, and is used in the "hot path" to draw the page. In particular it's used to crate the dropdown for the search bar, and to append a list of crates to the sidebar (on some pages). Skip early search that can bypass 500ms timeout. This was occurring when someone had typed some text during the load of search-index.js. Their query was usually not ready to execute, and the search itself is fairly expensive, delaying the overall load, which delayed the input / keyup events, which delayed eventually executing the query.
2021-02-27Auto merge of #82511 - jsha:fix-bfcache2, r=GuillaumeGomezbors-6/+14
Fix back-forward cache in rustdoc frontend Rustdoc's frontend set a no-op unload handler, specifically to disable Firefox's back-forward cache because it caused a bug. It's nice to allow the back-forward cache because it permits faster navigations. This change addresses the issues that were caused by back-forward cache. https://developer.mozilla.org/en-US/docs/Mozilla/Firefox/Releases/1.5/Using_Firefox_1.5_caching https://web.dev/bfcache/ Demo: https://jacob.hoffman-andrews.com/rust/fix-bfcache/std/string/struct.String.html Related: #72272
2021-02-24Fix back-forward cache in rustdoc frontend.Jacob Hoffman-Andrews-6/+14
Rustdoc's frontend set a no-op unload handler, specifically to disable Firefox's back-forward cache because it caused a bug. It's nice to allow the back-forward cache because it permits faster navigations. This change addresses the issues that were caused by back-forward cache. https://developer.mozilla.org/en-US/docs/Mozilla/Firefox/Releases/1.5/Using_Firefox_1.5_caching https://web.dev/bfcache/
2021-02-23Rollup merge of #82234 - GuillaumeGomez:remove-query-param-on-esc, r=Nemo157Dylan DPC-1/+6
Remove query parameters when skipping search results Fixes #81330. This PR changes the following: when pressing ESC and that no other "action" was performed (understand: no closing the search result, or hiding a menu or something along the line), then we discard the URL query parameters (the `?whatever=dsjfs`). What do you think about this change ```@rust-lang/rustdoc``` ? EDIT: finally we're simply removing the query parameter when we're skipping the search results. r? ```@Nemo157```
2021-02-17Remove query parameters when leaving search resultsGuillaume Gomez-1/+6
2021-02-15Fix ES5 errors (IE11)Guillaume Gomez-5/+11
2021-02-02Better styling of "Switch result tab" shortcutSmitty-1/+1
2021-02-01Rollup merge of #81592 - GuillaumeGomez:rustdoc-ui-fixes, r=Nemo157Jonas Schievink-9/+0
Rustdoc UI fixes The first commit fixes this bug (I couldn't figure out why we were setting the width manually and it works as expected without so...): ![Screenshot from 2021-01-31 12-58-46](https://user-images.githubusercontent.com/3050060/106384371-d56a7700-63ca-11eb-9e04-c06b40c2ab5e.png) The second commit fixes a small bug. On tablets or computer with very little width, the search section goes "over" the search input, making it impossible to click on the search input: ![Screenshot from 2021-01-31 13-22-37](https://user-images.githubusercontent.com/3050060/106384413-021e8e80-63cb-11eb-8321-391a1f8a4c7e.png) The third and last commit fixes two bugs that you can see in this screenshot: ![Screenshot from 2021-01-31 13-41-05](https://user-images.githubusercontent.com/3050060/106384424-0cd92380-63cb-11eb-82de-76218286c3fb.png) The wheel is going over the search input and the search tab is going under the search results text. The bug was fixed by simply switching to "mobile mode" at a bigger width: ![Screenshot from 2021-01-31 13-49-50](https://user-images.githubusercontent.com/3050060/106384466-4447d000-63cb-11eb-9330-a7cd29403905.png) cc ```@pickfire``` r? ```@Nemo157```
2021-01-31Remove unneeded explicit width from search resultsGuillaume Gomez-9/+0
2021-01-28Rollup merge of #81379 - GuillaumeGomez:improve-urls, r=Nemo157Yuki Okushi-7/+17
Improve URLs handling Fixes #81330. Explanations: before this PR, when emptying the search input, we still had `?search=` in the URL, which wasn't very nice. Now, if the search is empty, we drop the `?search=` part. Also, I realized while working on this PR that when we clicked on a menu link when we were on the search results, the search parameters would look like: `?search=#the-anchor`, which was super weird. Now, it looks like this: `?search=the-search#the-anchor`. Also, I didn't use the `Url` very nice API because it's not available in any IE version (sadness...). cc `````@lzutao````` r? `````@Nemo157`````
2021-01-25Improve URL handling when clicking on a menu link while being on the search ↵Guillaume Gomez-7/+16
results and overall
2021-01-25Completely remove search query parameter when clearing search inputGuillaume Gomez-1/+2
2021-01-25Fix some bugs reported by eslintGuillaume Gomez-28/+22
2021-01-19Rollup merge of #81161 - GuillaumeGomez:remove-inline-script, r=Nemo157Guillaume Gomez-12/+27
Remove inline script tags Fixes #81133. cc ``@pietroalbini`` r? ``@Nemo157``
2021-01-19Rollup merge of #80382 - GuillaumeGomez:search-result-tab-picking, ↵Guillaume Gomez-0/+15
r=Nemo157,pickfire Improve search result tab handling Fixes #80378. If the current search result tab is empty, it picks the first non-empty one. If all are empty, the current one doesn't change. It can be tested with "-> string" (where only the "returned elements" tab is not empty). r? `@jyn514`
2021-01-18Remove inline script tagsGuillaume Gomez-12/+27
2021-01-15Use Array.some instead of onEach to have better performanceGuillaume Gomez-1/+1
2021-01-15Improve JS performance by storing length before comparing to it in loopsGuillaume Gomez-53/+45
2021-01-04Auto merge of #80554 - GuillaumeGomez:more-js-cleanup, r=jyn514bors-18/+12
More js cleanup Part of #79052 (Same kind as #80515). This one is about some small fixes: * Replacing some loops with `onEachLazy`. * Removing unused function arguments. * Turn `buildHelperPopup` into a variable so it can be "replaced" once the function has been called once so it's not called again. r? `@jyn514`
2021-01-03Inline resetMouseMoved function directly into "mousemove" event handlerGuillaume Gomez-5/+1
2021-01-03Replace some loops with "onEachLazy" callGuillaume Gomez-13/+11
2020-12-31Use Array.prototype.filter instead of open-codingMichael Howell-7/+1
Part of #79052, originally suggested in https://github.com/rust-lang/rust/pull/79052#discussion_r523468743 Co-authored-by: Joshua Nelson <joshua@yottadb.com>
2020-12-30If the current search result tab is empty, it picks the first non-empty one. ↵Guillaume Gomez-0/+15
If all are empty, the current one doesn't change.