From a272007a209a4327ad8122af1ad9f9620f04724e Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Tue, 2 Apr 2024 07:55:52 -0700 Subject: [PATCH] Clean up src/librustdoc/html/render/search_index/encode.rs Co-authored-by: Guillaume Gomez --- .../html/render/search_index/encode.rs | 46 +++++++++---------- 1 file changed, 22 insertions(+), 24 deletions(-) diff --git a/src/librustdoc/html/render/search_index/encode.rs b/src/librustdoc/html/render/search_index/encode.rs index af5eccd5bed..54407c614c4 100644 --- a/src/librustdoc/html/render/search_index/encode.rs +++ b/src/librustdoc/html/render/search_index/encode.rs @@ -92,24 +92,23 @@ fn try_make_run(&mut self) -> bool { r += !chunk & u64::from((chunk << 1).count_ones()); r += !next_chunk & u64::from((chunk >> 63).count_ones()); } - if (2 + 4 * r) < 8192 { - let bits = std::mem::replace(bits, Box::new([0; 1024])); - *self = Container::Run(Vec::new()); - for (i, bits) in bits.iter().copied().enumerate() { - if bits == 0 { - continue; - } - for j in 0..64 { - let value = (u16::try_from(i).unwrap() << 6) | j; - if bits & (1 << j) != 0 { - self.push(value); - } + if (2 + 4 * r) >= 8192 { + return false; + } + let bits = std::mem::replace(bits, Box::new([0; 1024])); + *self = Container::Run(Vec::new()); + for (i, bits) in bits.iter().copied().enumerate() { + if bits == 0 { + continue; + } + for j in 0..64 { + let value = (u16::try_from(i).unwrap() << 6) | j; + if bits & (1 << j) != 0 { + self.push(value); } } - true - } else { - false } + true } Container::Array(array) if array.len() <= 5 => false, Container::Array(array) => { @@ -121,16 +120,15 @@ fn try_make_run(&mut self) -> bool { } prev = Some(value); } - if 2 + 4 * r < 2 * array.len() + 2 { - let array = std::mem::replace(array, Vec::new()); - *self = Container::Run(Vec::new()); - for value in array { - self.push(value); - } - true - } else { - false + if 2 + 4 * r >= 2 * array.len() + 2 { + return false; } + let array = std::mem::replace(array, Vec::new()); + *self = Container::Run(Vec::new()); + for value in array { + self.push(value); + } + true } Container::Run(_) => true, }