-
Notifications
You must be signed in to change notification settings - Fork 12.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[rustdoc] Use Map instead of Object for source files and search index #118910
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -167,23 +167,24 @@ pub(super) fn write_shared( | |
let mut krates = Vec::new(); | ||
|
||
if path.exists() { | ||
let prefix = format!("\"{krate}\""); | ||
let prefix = format!("[\"{krate}\""); | ||
for line in BufReader::new(File::open(path)?).lines() { | ||
let line = line?; | ||
if !line.starts_with('"') { | ||
if !line.starts_with("[\"") { | ||
continue; | ||
} | ||
if line.starts_with(&prefix) { | ||
continue; | ||
} | ||
if line.ends_with(",\\") { | ||
if line.ends_with("],\\") { | ||
ret.push(line[..line.len() - 2].to_string()); | ||
} else { | ||
// Ends with "\\" (it's the case for the last added crate line) | ||
ret.push(line[..line.len() - 1].to_string()); | ||
} | ||
krates.push( | ||
line.split('"') | ||
line[1..] // We skip the `[` parent at the beginning of the line. | ||
.split('"') | ||
.find(|s| !s.is_empty()) | ||
.map(|s| s.to_owned()) | ||
.unwrap_or_else(String::new), | ||
|
@@ -285,7 +286,7 @@ pub(super) fn write_shared( | |
let (mut all_sources, _krates) = | ||
try_err!(collect_json(&dst, krate.name(cx.tcx()).as_str()), &dst); | ||
all_sources.push(format!( | ||
r#""{}":{}"#, | ||
r#"["{}",{}]"#, | ||
&krate.name(cx.tcx()), | ||
hierarchy | ||
.to_json_string() | ||
|
@@ -296,9 +297,9 @@ pub(super) fn write_shared( | |
.replace("\\\"", "\\\\\"") | ||
)); | ||
all_sources.sort(); | ||
let mut v = String::from("var srcIndex = JSON.parse('{\\\n"); | ||
let mut v = String::from("const srcIndex = new Map(JSON.parse('[\\\n"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, crud. The test cases pass, but this has a race condition. I'll open a PR to fix it in a few minutes. |
||
v.push_str(&all_sources.join(",\\\n")); | ||
v.push_str("\\\n}');\ncreateSrcSidebar();\n"); | ||
v.push_str("\\\n]'));\ncreateSrcSidebar();\n"); | ||
Ok(v.into_bytes()) | ||
}; | ||
write_invocation_specific("src-files.js", &make_sources)?; | ||
|
@@ -316,11 +317,11 @@ pub(super) fn write_shared( | |
// with rustdoc running in parallel. | ||
all_indexes.sort(); | ||
write_invocation_specific("search-index.js", &|| { | ||
let mut v = String::from("var searchIndex = JSON.parse('{\\\n"); | ||
let mut v = String::from("const searchIndex = new Map(JSON.parse('[\\\n"); | ||
v.push_str(&all_indexes.join(",\\\n")); | ||
v.push_str( | ||
r#"\ | ||
}'); | ||
]')); | ||
if (typeof window !== 'undefined' && window.initSearch) {window.initSearch(searchIndex)}; | ||
if (typeof exports !== 'undefined') {exports.searchIndex = searchIndex}; | ||
"#, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefer not to make changes that add more bytes to these files. Instead, could we keep the object representation in JSON and add a function to convert to a map at the end?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hum, that kinda kills the original point. Do you mind running a perf check on this already before I make the change please? Like that we'll be able to see if how we transform into a
Map
changes anything.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, that makes sense.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh I meant on your JS perf check (I don't think there will be any change on the rust side). I couldn't find it on your profile. ^^'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://gitlab.com/notriddle/rustdoc-js-profile
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was looking on github so now I understand why I didn't find it... Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There doesn’t seem to be any significant difference in doc bytes.
I’ll try running the performance test on it as soon as the merge conflicts are resolved.