Skip to content

Commit 68a9c0e

Browse files
Auto merge of #148522 - yotamofek:pr/rustdoc/optimize-read_postings_from_string, r=<try>
Micro-optimize rustdoc search index parsing
2 parents 8e0b68e + ab769ec commit 68a9c0e

File tree

1 file changed

+3
-10
lines changed
  • src/librustdoc/html/render/search_index

1 file changed

+3
-10
lines changed

src/librustdoc/html/render/search_index/encode.rs

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -78,16 +78,9 @@ pub fn read_postings_from_string(postings: &mut Vec<Vec<u32>>, mut buf: &[u8]) {
7878
while let Some(&c) = buf.get(0) {
7979
if c < 0x3a {
8080
buf = &buf[1..];
81-
let mut slot = Vec::new();
82-
for _ in 0..c {
83-
slot.push(
84-
(buf[0] as u32)
85-
| ((buf[1] as u32) << 8)
86-
| ((buf[2] as u32) << 16)
87-
| ((buf[3] as u32) << 24),
88-
);
89-
buf = &buf[4..];
90-
}
81+
let buf = buf.split_off(..usize::from(c) * size_of::<u32>()).unwrap();
82+
let (chunks, _) = buf.as_chunks();
83+
let slot = chunks.iter().copied().map(u32::from_le_bytes).collect();
9184
postings.push(slot);
9285
} else {
9386
let (bitmap, consumed_bytes_len) =

0 commit comments

Comments
 (0)