More clippy suggestions

This commit is contained in:
Wilson Lin 2021-08-06 23:23:05 +10:00
parent 28944e33a4
commit db7ae23404
6 changed files with 19 additions and 24 deletions

View File

@ -97,7 +97,7 @@ impl std::ops::Index<u8> for Lookup {
}) })
.map( .map(
([name, points]) => ` ([name, points]) => `
pub static ${name}: &'static Lookup = &Lookup { pub static ${name}: &Lookup = &Lookup {
table: [${Array.from({ length: 256 }, (_, i) => points.includes(i)).join( table: [${Array.from({ length: 256 }, (_, i) => points.includes(i)).join(
", " ", "
)}], )}],

View File

@ -26,10 +26,10 @@ for (const [encoded, entity] of Object.entries(entities)) {
} }
const output = ` const output = `
pub static SHORTER_ENCODED_ENTITIES_ENCODED: &[&'static [u8]] = &[ pub static SHORTER_ENCODED_ENTITIES_ENCODED: &[&[u8]] = &[
${shorterEncodedEntities.map(([encoded, _]) => encoded).join(",\n ")} ${shorterEncodedEntities.map(([encoded, _]) => encoded).join(",\n ")}
]; ];
pub static SHORTER_ENCODED_ENTITIES_DECODED: &[&'static [u8]] = &[ pub static SHORTER_ENCODED_ENTITIES_DECODED: &[&[u8]] = &[
${shorterEncodedEntities.map(([_, decoded]) => decoded).join(",\n ")} ${shorterEncodedEntities.map(([_, decoded]) => decoded).join(",\n ")}
]; ];

View File

@ -171,7 +171,7 @@ export class TrieBuilder {
const name = `${this.name}_NODE_${this.nextId++}`; const name = `${this.name}_NODE_${this.nextId++}`;
this.variables.push( this.variables.push(
`static ${name}: &'static crate::pattern::TrieNode<${this.valueType}> = ${varValue};` `static ${name}: &crate::pattern::TrieNode<${this.valueType}> = ${varValue};`
); );
this.codeCache.set(varValue, name); this.codeCache.set(varValue, name);
return name; return name;

View File

@ -65,15 +65,13 @@ pub fn minify_content(
match n { match n {
NodeData::Element { name, .. } => { NodeData::Element { name, .. } => {
if index_of_last_nonempty_text_or_elem > -1 { if index_of_last_nonempty_text_or_elem > -1 {
match &mut previous_nodes[index_of_last_nonempty_text_or_elem as usize] { if let NodeData::Element {
NodeData::Element { next_sibling_element_name,
next_sibling_element_name, ..
.. } = &mut previous_nodes[index_of_last_nonempty_text_or_elem as usize]
} => { {
debug_assert!(next_sibling_element_name.is_empty()); debug_assert!(next_sibling_element_name.is_empty());
next_sibling_element_name.extend_from_slice(name); next_sibling_element_name.extend_from_slice(name);
}
_ => {}
}; };
}; };
found_first_text_or_elem = true; found_first_text_or_elem = true;
@ -106,9 +104,10 @@ pub fn minify_content(
}; };
} }
if trim && index_of_last_text_or_elem > -1 { if trim && index_of_last_text_or_elem > -1 {
match nodes.get_mut(index_of_last_text_or_elem as usize).unwrap() { if let NodeData::Text { value } =
NodeData::Text { value } => right_trim(value), nodes.get_mut(index_of_last_text_or_elem as usize).unwrap()
_ => {} {
right_trim(value);
}; };
} }

View File

@ -59,10 +59,7 @@ impl<'c> Code<'c> {
} }
pub fn shift_if_next_not_in_lookup(&mut self, lookup: &'static Lookup) -> Option<u8> { pub fn shift_if_next_not_in_lookup(&mut self, lookup: &'static Lookup) -> Option<u8> {
let c = self let c = self.code.get(self.next).filter(|&&n| !lookup[n]).copied();
.code
.get(self.next)
.filter(|&&n| !lookup[n]).copied();
if c.is_some() { if c.is_some() {
self.next += 1; self.next += 1;
}; };

View File

@ -59,10 +59,9 @@ impl<V: 'static + Copy> TrieNode<V> {
None | Some(None) => break, None | Some(None) => break,
}; };
pos += 1; pos += 1;
match node.value { if let Some(v) = node.value {
Some(v) => value = Some(TrieNodeMatch::Found { len: pos, value: v }), value = Some(TrieNodeMatch::Found { len: pos, value: v });
None => {} }
};
} }
value.unwrap_or(TrieNodeMatch::NotFound { reached: pos }) value.unwrap_or(TrieNodeMatch::NotFound { reached: pos })
} }