Skip to content
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

perf: accelerated datatype conversion #482

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@ edition = "2021"
rust-version = "1.73"

[dependencies]
atoi_simd = "0.16"
byteorder = "1.5"
codepage = "0.1.1"
encoding_rs = "0.8"
fast-float2 = "0.2"
log = "0.4"
serde = "1.0"
quick-xml = { version = "0.36", features = ["encoding"] }
Expand Down
12 changes: 6 additions & 6 deletions src/datatype.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ impl DataType for Data {
Data::Int(v) => Some(*v),
Data::Float(v) => Some(*v as i64),
Data::Bool(v) => Some(*v as i64),
Data::String(v) => v.parse::<i64>().ok(),
Data::String(v) => atoi_simd::parse::<i64>(v.as_bytes()).ok(),
_ => None,
}
}
Expand All @@ -164,7 +164,7 @@ impl DataType for Data {
Data::Int(v) => Some(*v as f64),
Data::Float(v) => Some(*v),
Data::Bool(v) => Some((*v as i32).into()),
Data::String(v) => v.parse::<f64>().ok(),
Data::String(v) => fast_float2::parse(v).ok(),
_ => None,
}
}
Expand Down Expand Up @@ -472,8 +472,8 @@ impl DataType for DataRef<'_> {
DataRef::Int(v) => Some(*v),
DataRef::Float(v) => Some(*v as i64),
DataRef::Bool(v) => Some(*v as i64),
DataRef::String(v) => v.parse::<i64>().ok(),
DataRef::SharedString(v) => v.parse::<i64>().ok(),
DataRef::String(v) => atoi_simd::parse::<i64>(v.as_bytes()).ok(),
DataRef::SharedString(v) => atoi_simd::parse::<i64>(v.as_bytes()).ok(),
_ => None,
}
}
Expand All @@ -483,8 +483,8 @@ impl DataType for DataRef<'_> {
DataRef::Int(v) => Some(*v as f64),
DataRef::Float(v) => Some(*v),
DataRef::Bool(v) => Some((*v as i32).into()),
DataRef::String(v) => v.parse::<f64>().ok(),
DataRef::SharedString(v) => v.parse::<f64>().ok(),
DataRef::String(v) => fast_float2::parse(v).ok(),
DataRef::SharedString(v) => fast_float2::parse(v).ok(),
_ => None,
}
}
Expand Down
16 changes: 4 additions & 12 deletions src/xlsx/cells_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,13 +195,8 @@ impl<'a> XlsxCellReader<'a> {
// shared index
let shared_index =
match get_attribute(e.attributes(), QName(b"si"))? {
Some(res) => match std::str::from_utf8(res) {
Ok(res) => match res.parse::<usize>() {
Ok(res) => res,
Err(e) => {
return Err(XlsxError::ParseInt(e));
}
},
Some(res) => match atoi_simd::parse::<usize>(res) {
Ok(res) => res,
Err(_) => {
return Err(XlsxError::Unexpected(
"si attribute must be a number",
Expand Down Expand Up @@ -332,18 +327,15 @@ fn read_v<'s>(
) -> Result<DataRef<'s>, XlsxError> {
let cell_format = match get_attribute(c_element.attributes(), QName(b"s")) {
Ok(Some(style)) => {
let id: usize = std::str::from_utf8(style)
.unwrap_or("0")
.parse()
.unwrap_or(0);
let id = atoi_simd::parse::<usize>(style).unwrap_or(0);
formats.get(id)
}
_ => Some(&CellFormat::Other),
};
match get_attribute(c_element.attributes(), QName(b"t"))? {
Some(b"s") => {
// shared string
let idx: usize = v.parse()?;
let idx = atoi_simd::parse::<usize>(v.as_bytes()).unwrap_or(0);
Ok(DataRef::SharedString(&strings[idx]))
}
Some(b"b") => {
Expand Down