Mercurial > hg
comparison rust/hg-core/src/revlog/index.rs @ 51272:c4cbb515b006
rust-clippy: apply some more trivial fixes
All of these were hinted at by clippy and make the code simpler.
author | Raphaël Gomès <rgomes@octobus.net> |
---|---|
date | Wed, 20 Dec 2023 14:59:31 +0100 |
parents | 47a34afda7ad |
children | b01e7d97e167 |
comparison
equal
deleted
inserted
replaced
51271:eab5b061cd48 | 51272:c4cbb515b006 |
---|---|
318 fn insert_for( | 318 fn insert_for( |
319 &mut self, | 319 &mut self, |
320 rev: BaseRevision, | 320 rev: BaseRevision, |
321 value: BaseRevision, | 321 value: BaseRevision, |
322 ) -> Result<(), RevlogError> { | 322 ) -> Result<(), RevlogError> { |
323 let all_values = self.entry(rev).or_insert_with(HashSet::new); | 323 let all_values = self.entry(rev).or_default(); |
324 all_values.insert(value); | 324 all_values.insert(value); |
325 Ok(()) | 325 Ok(()) |
326 } | 326 } |
327 } | 327 } |
328 | 328 |
939 return 0; | 939 return 0; |
940 } | 940 } |
941 let last_entry = &self.get_entry(revs[revs.len() - 1]).unwrap(); | 941 let last_entry = &self.get_entry(revs[revs.len() - 1]).unwrap(); |
942 let end = last_entry.c_start() + last_entry.compressed_len() as u64; | 942 let end = last_entry.c_start() + last_entry.compressed_len() as u64; |
943 let first_rev = revs.iter().find(|r| r.0 != NULL_REVISION.0).unwrap(); | 943 let first_rev = revs.iter().find(|r| r.0 != NULL_REVISION.0).unwrap(); |
944 let start = if (*first_rev).0 == 0 { | 944 let start = if first_rev.0 == 0 { |
945 0 | 945 0 |
946 } else { | 946 } else { |
947 self.get_entry(*first_rev).unwrap().c_start() | 947 self.get_entry(*first_rev).unwrap().c_start() |
948 }; | 948 }; |
949 (end - start) as usize | 949 (end - start) as usize |
1820 } | 1820 } |
1821 | 1821 |
1822 pub fn build(&self) -> Vec<u8> { | 1822 pub fn build(&self) -> Vec<u8> { |
1823 let mut bytes = Vec::with_capacity(INDEX_ENTRY_SIZE); | 1823 let mut bytes = Vec::with_capacity(INDEX_ENTRY_SIZE); |
1824 if self.is_first { | 1824 if self.is_first { |
1825 bytes.extend(&match (self.is_general_delta, self.is_inline) { | 1825 bytes.extend(match (self.is_general_delta, self.is_inline) { |
1826 (false, false) => [0u8, 0], | 1826 (false, false) => [0u8, 0], |
1827 (false, true) => [0u8, 1], | 1827 (false, true) => [0u8, 1], |
1828 (true, false) => [0u8, 2], | 1828 (true, false) => [0u8, 2], |
1829 (true, true) => [0u8, 3], | 1829 (true, true) => [0u8, 3], |
1830 }); | 1830 }); |
1831 bytes.extend(&self.version.to_be_bytes()); | 1831 bytes.extend(self.version.to_be_bytes()); |
1832 // Remaining offset bytes. | 1832 // Remaining offset bytes. |
1833 bytes.extend(&[0u8; 2]); | 1833 bytes.extend([0u8; 2]); |
1834 } else { | 1834 } else { |
1835 // Offset stored on 48 bits (6 bytes) | 1835 // Offset stored on 48 bits (6 bytes) |
1836 bytes.extend(&(self.offset as u64).to_be_bytes()[2..]); | 1836 bytes.extend(&(self.offset as u64).to_be_bytes()[2..]); |
1837 } | 1837 } |
1838 bytes.extend(&[0u8; 2]); // Revision flags. | 1838 bytes.extend([0u8; 2]); // Revision flags. |
1839 bytes.extend(&(self.compressed_len as u32).to_be_bytes()); | 1839 bytes.extend((self.compressed_len as u32).to_be_bytes()); |
1840 bytes.extend(&(self.uncompressed_len as u32).to_be_bytes()); | 1840 bytes.extend((self.uncompressed_len as u32).to_be_bytes()); |
1841 bytes.extend( | 1841 bytes.extend( |
1842 &self.base_revision_or_base_of_delta_chain.0.to_be_bytes(), | 1842 self.base_revision_or_base_of_delta_chain.0.to_be_bytes(), |
1843 ); | 1843 ); |
1844 bytes.extend(&self.link_revision.0.to_be_bytes()); | 1844 bytes.extend(self.link_revision.0.to_be_bytes()); |
1845 bytes.extend(&self.p1.0.to_be_bytes()); | 1845 bytes.extend(self.p1.0.to_be_bytes()); |
1846 bytes.extend(&self.p2.0.to_be_bytes()); | 1846 bytes.extend(self.p2.0.to_be_bytes()); |
1847 bytes.extend(self.node.as_bytes()); | 1847 bytes.extend(self.node.as_bytes()); |
1848 bytes.extend(vec![0u8; 12]); | 1848 bytes.extend(vec![0u8; 12]); |
1849 bytes | 1849 bytes |
1850 } | 1850 } |
1851 } | 1851 } |