diff options
| author | Dylan DPC <dylan.dpc@gmail.com> | 2020-04-20 18:07:05 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-04-20 18:07:05 +0200 |
| commit | 2f06ac08e923a146134199cdb72c08b85a800203 (patch) | |
| tree | 75ae2e1fbbcd69f3d0a436e9745279b7b6d6cf61 /src/librustdoc/html/render | |
| parent | 8ce3f840ae9b735a66531996c32330f24b877cb0 (diff) | |
| parent | b4fb3069ce82f61f84a9487d17fb96389d55126a (diff) | |
| download | rust-2f06ac08e923a146134199cdb72c08b85a800203.tar.gz rust-2f06ac08e923a146134199cdb72c08b85a800203.zip | |
Rollup merge of #71250 - GuillaumeGomez:use-json-instead-of-js, r=kinnison
Replace big JS dict with JSON parsing Part of #56545. @ollie27 suggested that using JSON instead of a JS dict might be faster, so I decided to test it. And the results far exceeded whatever expectations I had... I used https://github.com/adamgreig/stm32ral for my tests. If you want to build it locally: ```bash $ cargo doc --features doc --open ``` But I strongly recommend to do it with this PR. Some numbers: * Loading a page with the JSON search-index: less than 1 second * Loading a page with the JS search-index: crashed after 30 seconds I think the results are clear enough... r? @ollie27 cc @rust-lang/rustdoc
Diffstat (limited to 'src/librustdoc/html/render')
| -rw-r--r-- | src/librustdoc/html/render/cache.rs | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/src/librustdoc/html/render/cache.rs b/src/librustdoc/html/render/cache.rs index f3c5c12810b..5b090291227 100644 --- a/src/librustdoc/html/render/cache.rs +++ b/src/librustdoc/html/render/cache.rs @@ -634,7 +634,7 @@ fn build_index(krate: &clean::Crate, cache: &mut Cache) -> String { // Collect the index into a string format!( - r#"searchIndex["{}"] = {};"#, + r#""{}":{}"#, krate.name, serde_json::to_string(&CrateData { doc: crate_doc, @@ -642,6 +642,11 @@ fn build_index(krate: &clean::Crate, cache: &mut Cache) -> String { paths: crate_paths, }) .expect("failed serde conversion") + // All these `replace` calls are because we have to go through JS string for JSON content. + .replace(r"\", r"\\") + .replace("'", r"\'") + // We need to escape double quotes for the JSON. + .replace("\\\"", "\\\\\"") ) } |
