mirror of
https://github.com/meilisearch/MeiliSearch
synced 2024-12-23 21:20:24 +01:00
Do not allocate when parsing CSV headers
This commit is contained in:
parent
ce90fc628a
commit
048e174efb
@ -108,7 +108,7 @@ impl<W: io::Write + io::Seek> DocumentBatchBuilder<W> {
|
||||
.headers()?
|
||||
.into_iter()
|
||||
.map(parse_csv_header)
|
||||
.map(|(k, t)| (this.index.insert(&k), t))
|
||||
.map(|(k, t)| (this.index.insert(k), t))
|
||||
.collect::<BTreeMap<_, _>>();
|
||||
|
||||
for (i, record) in records.into_records().enumerate() {
|
||||
@ -161,16 +161,16 @@ enum AllowedType {
|
||||
Number,
|
||||
}
|
||||
|
||||
fn parse_csv_header(header: &str) -> (String, AllowedType) {
|
||||
fn parse_csv_header(header: &str) -> (&str, AllowedType) {
|
||||
// if there are several separators we only split on the last one.
|
||||
match header.rsplit_once(':') {
|
||||
Some((field_name, field_type)) => match field_type {
|
||||
"string" => (field_name.to_string(), AllowedType::String),
|
||||
"number" => (field_name.to_string(), AllowedType::Number),
|
||||
"string" => (field_name, AllowedType::String),
|
||||
"number" => (field_name, AllowedType::Number),
|
||||
// if the pattern isn't reconized, we keep the whole field.
|
||||
_otherwise => (header.to_string(), AllowedType::String),
|
||||
_otherwise => (header, AllowedType::String),
|
||||
},
|
||||
None => (header.to_string(), AllowedType::String),
|
||||
None => (header, AllowedType::String),
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user