Skip to content

Commit b7ed7eb

Browse files
Clippy
1 parent 00fc16d commit b7ed7eb

File tree

2 files changed

+21
-21
lines changed

2 files changed

+21
-21
lines changed

src/classifier.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,13 @@ pub const HI_LOOKUP: [u8; 16] = [
4343
use crate::u8x16::u8x16;
4444

4545
#[derive(Debug)]
46-
pub(crate) struct CsvClassifier<'a> {
46+
pub struct CsvClassifier<'a> {
4747
cursor: usize,
4848
data: &'a [u8],
4949
}
5050

5151
impl<'a> CsvClassifier<'a> {
52-
pub fn new(data: &'a [u8]) -> Self {
52+
pub const fn new(data: &'a [u8]) -> Self {
5353
Self { cursor: 0, data }
5454
}
5555

src/reader.rs

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use std::ops::Range;
99
pub struct CsvReader {
1010
quotation_bitsets: Vec<u64>,
1111
comma_bitsets: Vec<u64>,
12-
whitespace_bitsets: Vec<u64>,
12+
new_line_bitsets: Vec<u64>,
1313
}
1414

1515
impl CsvReader {
@@ -18,22 +18,22 @@ impl CsvReader {
1818
let capacity = vectors.len() / 4 + 1;
1919

2020
let comma_broadcast = u8x16::broadcast(COMMA_CLASS);
21-
let whitespace_broadcast = u8x16::broadcast(NEW_LINE_CLASS);
21+
let new_line_broadcast = u8x16::broadcast(NEW_LINE_CLASS);
2222
let quotation_broadcast = u8x16::broadcast(QUOTATION_CLASS);
2323

2424
let mut comma_bitsets = Vec::with_capacity(capacity);
25-
let mut whitespace_bitsets = Vec::with_capacity(capacity);
25+
let mut new_line_bitsets = Vec::with_capacity(capacity);
2626
let mut quotation_bitsets = Vec::with_capacity(capacity);
2727

28-
vectors.chunks(4).into_iter().for_each(|chunk| {
28+
vectors.chunks(4).for_each(|chunk| {
2929
comma_bitsets.push(build_u64(chunk, comma_broadcast));
30-
whitespace_bitsets.push(build_u64(chunk, whitespace_broadcast));
30+
new_line_bitsets.push(build_u64(chunk, new_line_broadcast));
3131
quotation_bitsets.push(build_u64(chunk, quotation_broadcast));
3232
});
3333

3434
Self {
3535
comma_bitsets,
36-
whitespace_bitsets,
36+
new_line_bitsets,
3737
quotation_bitsets,
3838
}
3939
}
@@ -52,19 +52,19 @@ impl CsvReader {
5252
let outside_quotations = !mark_inside_quotations(valid_quotations);
5353

5454
let mut valid_commas = self.comma_bitsets[i] & outside_quotations;
55-
let mut valid_whitespace = self.whitespace_bitsets[i] & outside_quotations;
55+
let mut valid_new_line = self.new_line_bitsets[i] & outside_quotations;
5656

57-
if valid_commas == 0 && valid_whitespace == 0 {
57+
if valid_commas == 0 && valid_new_line == 0 {
5858
continue;
5959
}
6060

6161
let mut bitset_cursor = 0;
6262

6363
loop {
6464
let first_comma = valid_commas.leading_zeros() as usize;
65-
let first_whitespace = valid_whitespace.leading_zeros() as usize;
65+
let first_new_line = valid_new_line.leading_zeros() as usize;
6666

67-
let bits_traveled = first_comma.min(first_whitespace);
67+
let bits_traveled = first_comma.min(first_new_line);
6868

6969
if bits_traveled == 64 {
7070
break;
@@ -75,14 +75,14 @@ impl CsvReader {
7575
end: cursor + bitset_cursor + bits_traveled,
7676
});
7777

78-
if first_whitespace < first_comma {
78+
if first_new_line < first_comma {
7979
rows.push(Row::from(current_row.clone()));
8080
current_row.clear();
8181
}
8282

8383
bitset_cursor += bits_traveled + 1;
8484
valid_commas <<= bits_traveled + 1;
85-
valid_whitespace <<= bits_traveled + 1;
85+
valid_new_line <<= bits_traveled + 1;
8686
}
8787

8888
cursor += bitset_cursor;
@@ -92,7 +92,7 @@ impl CsvReader {
9292
}
9393
}
9494

95-
fn remove_escaped_quotations(q: u64) -> u64 {
95+
const fn remove_escaped_quotations(q: u64) -> u64 {
9696
let escaped = q & (q << 1);
9797
let escaped = escaped | (escaped >> 1);
9898

@@ -101,9 +101,9 @@ fn remove_escaped_quotations(q: u64) -> u64 {
101101

102102
/// `mark_inside_quotations` does a parallel xor to mark all bits inbetween a quote pair.
103103
/// Note because of how xor works, the closing quote will be marked as 0. This is fine since
104-
/// we use this to mask commas and whitespace in between quote pairs.
104+
/// we use this to mask commas and new_line in between quote pairs.
105105
#[inline]
106-
fn mark_inside_quotations(mut x: u64) -> u64 {
106+
const fn mark_inside_quotations(mut x: u64) -> u64 {
107107
x ^= x << 1;
108108
x ^= x << 2;
109109
x ^= x << 4;
@@ -141,7 +141,7 @@ mod tests {
141141
let csv_reader1 = CsvReader::new(&slice63);
142142

143143
assert_eq!(csv_reader1.quotation_bitsets.len(), 1);
144-
assert_eq!(csv_reader1.whitespace_bitsets.len(), 1);
144+
assert_eq!(csv_reader1.new_line_bitsets.len(), 1);
145145
assert_eq!(csv_reader1.comma_bitsets.len(), 1);
146146

147147
let mut longer_slice = vec![];
@@ -151,16 +151,16 @@ mod tests {
151151

152152
let csv_reader2 = CsvReader::new(&longer_slice);
153153
assert_eq!(csv_reader2.quotation_bitsets.len(), 2);
154-
assert_eq!(csv_reader2.whitespace_bitsets.len(), 2);
154+
assert_eq!(csv_reader2.new_line_bitsets.len(), 2);
155155
assert_eq!(csv_reader2.comma_bitsets.len(), 2);
156156

157157
assert_eq!(
158158
csv_reader1.quotation_bitsets[0],
159159
csv_reader2.quotation_bitsets[0]
160160
);
161161
assert_eq!(
162-
csv_reader1.whitespace_bitsets[0],
163-
csv_reader2.whitespace_bitsets[0]
162+
csv_reader1.new_line_bitsets[0],
163+
csv_reader2.new_line_bitsets[0]
164164
);
165165
assert_eq!(csv_reader1.comma_bitsets[0], csv_reader2.comma_bitsets[0]);
166166

0 commit comments

Comments
 (0)