Skip to content

Apply select clippy perf lints #374

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions csv-core/src/reader.rs
Original file line number Diff line number Diff line change
@@ -1238,11 +1238,11 @@ impl DfaClasses {
panic!("added too many classes")
}
self.classes[b as usize] = self.next_class as u8;
self.next_class = self.next_class + 1;
self.next_class += 1;
}

fn num_classes(&self) -> usize {
self.next_class as usize
self.next_class
}

/// Scan and copy the input bytes to the output buffer quickly.
10 changes: 4 additions & 6 deletions csv-core/src/writer.rs
Original file line number Diff line number Diff line change
@@ -28,7 +28,7 @@ impl WriterBuilder {
double_quote: true,
comment: None,
};
WriterBuilder { wtr: wtr }
WriterBuilder { wtr }
}

/// Builder a CSV writer from this configuration.
@@ -191,12 +191,10 @@ pub struct Writer {
impl Clone for Writer {
fn clone(&self) -> Writer {
let mut requires_quotes = [false; 256];
for i in 0..256 {
requires_quotes[i] = self.requires_quotes[i];
}
requires_quotes.copy_from_slice(&self.requires_quotes);
Writer {
state: self.state.clone(),
requires_quotes: requires_quotes,
requires_quotes,
delimiter: self.delimiter,
term: self.term,
style: self.style,
@@ -518,7 +516,7 @@ pub fn is_non_numeric(input: &[u8]) -> bool {
// I suppose this could be faster if we wrote validators of numbers instead
// of using the actual parser, but that's probably a lot of work for a bit
// of a niche feature.
!s.parse::<f64>().is_ok() && !s.parse::<i128>().is_ok()
s.parse::<f64>().is_err() && s.parse::<i128>().is_err()
}

/// Escape quotes `input` and writes the result to `output`.
2 changes: 1 addition & 1 deletion src/byte_record.rs
Original file line number Diff line number Diff line change
@@ -698,7 +698,7 @@ impl Bounds {
/// If there are no fields, this returns `0`.
#[inline]
fn end(&self) -> usize {
self.ends().last().map(|&i| i).unwrap_or(0)
self.ends().last().copied().unwrap_or(0)
}

/// Returns the number of fields in these bounds.
12 changes: 6 additions & 6 deletions src/deserializer.rs
Original file line number Diff line number Diff line change
@@ -29,7 +29,7 @@ pub fn deserialize_string_record<'de, D: Deserialize<'de>>(
});
D::deserialize(&mut deser).map_err(|err| {
Error::new(ErrorKind::Deserialize {
pos: record.position().map(Clone::clone),
pos: record.position().cloned(),
err,
})
})
@@ -46,7 +46,7 @@ pub fn deserialize_byte_record<'de, D: Deserialize<'de>>(
});
D::deserialize(&mut deser).map_err(|err| {
Error::new(ErrorKind::Deserialize {
pos: record.position().map(Clone::clone),
pos: record.position().cloned(),
err,
})
})
@@ -284,7 +284,7 @@ impl<'r> DeRecord<'r> for DeByteRecord<'r> {

#[inline]
fn peek_field(&mut self) -> Option<&'r [u8]> {
self.it.peek().map(|s| *s)
self.it.peek().copied()
}

fn error(&self, kind: DeserializeErrorKind) -> DeserializeError {
@@ -329,8 +329,8 @@ macro_rules! deserialize_int {
visitor: V,
) -> Result<V::Value, Self::Error> {
let field = self.next_field()?;
let num = if field.starts_with("0x") {
<$inttype>::from_str_radix(&field[2..], 16)
let num = if let Some(stripped) = field.strip_prefix("0x") {
<$inttype>::from_str_radix(stripped, 16)
} else {
field.parse()
};
@@ -425,7 +425,7 @@ impl<'a, 'de: 'a, T: DeRecord<'de>> Deserializer<'de>
self,
visitor: V,
) -> Result<V::Value, Self::Error> {
self.next_field().and_then(|f| visitor.visit_str(f.into()))
self.next_field().and_then(|f| visitor.visit_str(f))
}

fn deserialize_bytes<V: Visitor<'de>>(
8 changes: 4 additions & 4 deletions src/reader.rs
Original file line number Diff line number Diff line change
@@ -1330,7 +1330,7 @@ impl<R: io::Read> Reader<R> {
match headers.string_record {
Ok(ref record) => Ok(record),
Err(ref err) => Err(Error::new(ErrorKind::Utf8 {
pos: headers.byte_record.position().map(Clone::clone),
pos: headers.byte_record.position().cloned(),
err: err.clone(),
})),
}
@@ -1887,7 +1887,7 @@ impl ReaderState {
Some(expected) => {
if record.len() as u64 != expected {
return Err(Error::new(ErrorKind::UnequalLengths {
pos: record.position().map(Clone::clone),
pos: record.position().cloned(),
expected_len: expected,
len: record.len() as u64,
}));
@@ -1915,7 +1915,7 @@ impl<R: io::Read, D: DeserializeOwned> DeserializeRecordsIntoIter<R, D> {
let headers = if !rdr.state.has_headers {
None
} else {
rdr.headers().ok().map(Clone::clone)
rdr.headers().ok().cloned()
};
DeserializeRecordsIntoIter {
rdr,
@@ -1973,7 +1973,7 @@ impl<'r, R: io::Read, D: DeserializeOwned> DeserializeRecordsIter<'r, R, D> {
let headers = if !rdr.state.has_headers {
None
} else {
rdr.headers().ok().map(Clone::clone)
rdr.headers().ok().cloned()
};
DeserializeRecordsIter {
rdr,
2 changes: 1 addition & 1 deletion src/string_record.rs
Original file line number Diff line number Diff line change
@@ -664,7 +664,7 @@ impl ops::Index<usize> for StringRecord {
impl<T: AsRef<str>> From<Vec<T>> for StringRecord {
#[inline]
fn from(xs: Vec<T>) -> StringRecord {
StringRecord::from_iter(xs.into_iter())
StringRecord::from_iter(xs)
}
}