Skip to content

Commit b95d379

Browse files
committed
Optimize a bit
It's better to allocate for the smaller prefix that we're extracting than to allocate repeatedly for the tail items, especially as `split_off` doesn't shrink the capacity of what we go on to insert.
1 parent 4711485 commit b95d379

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

mdbook-spec/src/std_links.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ pub fn std_links(book: &mut Book) {
5555
.captures_iter(&generated)
5656
.map(|cap| cap.get(1).unwrap().as_str())
5757
.collect();
58+
let mut urls = &mut urls[..];
5859
let expected_len: usize = chapter_links.values().map(|l| l.len()).sum();
5960
if urls.len() != expected_len {
6061
eprintln!(
@@ -67,9 +68,9 @@ pub fn std_links(book: &mut Book) {
6768
// Unflatten the urls list so that it is split back by chapter.
6869
let mut ch_urls: HashMap<&PathBuf, Vec<_>> = HashMap::new();
6970
for (ch_path, links) in &chapter_links {
70-
let rest = urls.split_off(links.len());
71-
ch_urls.insert(ch_path, urls);
72-
urls = rest;
71+
let xs;
72+
(xs, urls) = urls.split_at_mut(links.len());
73+
ch_urls.insert(ch_path, xs.into());
7374
}
7475

7576
// Do this in two passes to deal with lifetimes.

0 commit comments

Comments
 (0)