From 00c104225fad5d3eb27dc37719d9b6c26844c389 Mon Sep 17 00:00:00 2001 From: binarycat Date: Thu, 5 Jun 2025 18:42:54 -0500 Subject: rustdoc: make srcIndex no longer a global variable this is one-time initialization data, it can just be a function parameter. we also move the json parsing into createSrcSidebar to save a few bytes. --- src/librustdoc/html/static/js/src-script.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'src/librustdoc/html/static/js/src-script.js') diff --git a/src/librustdoc/html/static/js/src-script.js b/src/librustdoc/html/static/js/src-script.js index b9ab6e85603..0c6afbeed22 100644 --- a/src/librustdoc/html/static/js/src-script.js +++ b/src/librustdoc/html/static/js/src-script.js @@ -1,6 +1,3 @@ -// From rust: -/* global srcIndex */ - // Local js definitions: /* global addClass, onEachLazy, removeClass, browserSupportsHistoryApi */ /* global updateLocalStorage, getVar, nonnull */ @@ -100,11 +97,15 @@ window.rustdocToggleSrcSidebar = () => { // This function is called from "src-files.js", generated in `html/render/write_shared.rs`. // eslint-disable-next-line no-unused-vars -function createSrcSidebar() { +/** + * @param {string} srcIndexStr - strinified json map from crate name to dir structure + */ +function createSrcSidebar(srcIndexStr) { const container = nonnull(document.querySelector("nav.sidebar")); const sidebar = document.createElement("div"); sidebar.id = "src-sidebar"; + const srcIndex = new Map(JSON.parse(srcIndexStr)); let hasFoundFile = false; -- cgit 1.4.1-3-g733a5