Weird optimizations
This commit is contained in:
parent
f00c1de4d0
commit
ea97579ff2
31
src/main.rs
31
src/main.rs
|
@ -12,7 +12,7 @@ mod test;
|
|||
|
||||
#[derive(Error, Debug)]
|
||||
#[allow(clippy::enum_variant_names)]
|
||||
enum CifError {
|
||||
pub enum CifError {
|
||||
#[error("The CIF number string was too long")]
|
||||
CapacityError,
|
||||
#[error("CIF Number is invalid: {0:?}")]
|
||||
|
@ -63,7 +63,10 @@ fn join_to_arraystring<const C: usize>(elems: &[&str], str: &mut ArrayString<C>)
|
|||
if i > 0 {
|
||||
str.try_push(' ')?;
|
||||
}
|
||||
str.try_push_str(item)?;
|
||||
for c in item.chars() {
|
||||
str.try_push(c)?;
|
||||
}
|
||||
//str.try_push_str(item)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
@ -98,7 +101,7 @@ fn unfuck_cif_number(number: &str) -> Result<u32> {
|
|||
let thousands = match *word {
|
||||
"tysiąc" => {
|
||||
if i == 0 {
|
||||
&1_u16
|
||||
1_u16
|
||||
} else {
|
||||
return Err(GrammarError(number.to_string()))
|
||||
}
|
||||
|
@ -106,7 +109,7 @@ fn unfuck_cif_number(number: &str) -> Result<u32> {
|
|||
"tysięcy" | "tysiące" => {
|
||||
if i > 0 {
|
||||
join_to_arraystring(&split[..i], &mut buf)?;
|
||||
nummap::U16_NUMMAP.get(&buf).ok_or_else(|| GrammarError(number.to_string()))?
|
||||
nummap::get_u16(&buf)
|
||||
} else {
|
||||
return Err(GrammarError(number.to_string()))
|
||||
}
|
||||
|
@ -116,22 +119,28 @@ fn unfuck_cif_number(number: &str) -> Result<u32> {
|
|||
let remainder = if i + 1 < splitlen {
|
||||
buf.clear();
|
||||
join_to_arraystring(&split[i + 1..], &mut buf)?;
|
||||
nummap::U16_NUMMAP.get(&buf).ok_or_else(|| GrammarError(number.to_string()))?
|
||||
nummap::get_u16(&buf)
|
||||
} else {
|
||||
&0_u16
|
||||
0_u16
|
||||
};
|
||||
return Ok(u32::from(*thousands) * 1000 + u32::from(*remainder))
|
||||
return Ok(u32::from(thousands) * 1000 + u32::from(remainder))
|
||||
}
|
||||
Ok(u32::from(*nummap::U16_NUMMAP.get(number).ok_or_else(|| GrammarError(number.to_string()))?))
|
||||
Ok(u32::from(nummap::get_u16(&buf)))
|
||||
}
|
||||
|
||||
fn unfuck_cif_number_fast(number: &str) -> Result<u8> {
|
||||
assert_trailing_leading(number)?;
|
||||
let mut buf = ArrayString::<2048>::new();
|
||||
let mut buf = ArrayString::<2014>::new();
|
||||
let split = number.split_ascii_whitespace().take(8).collect::<ArrayVec<_, 64>>();
|
||||
|
||||
join_to_arraystring(&split, &mut buf)?;
|
||||
let number = *(nummap::U8_NUMMAP.get(&buf).ok_or_else(|| InvalidPixelError(number.to_string()))?);
|
||||
/*for (i, item) in split.iter().enumerate() {
|
||||
if i > 0 {
|
||||
buf.push(' ');
|
||||
}
|
||||
buf.push_str(item);
|
||||
}*/
|
||||
let number = nummap::get_u8(&buf);
|
||||
|
||||
Ok(number)
|
||||
}
|
||||
|
@ -142,7 +151,7 @@ fn unfuck_color_type(color_type: &str) -> Result<ColorType> {
|
|||
let split = color_type.split_ascii_whitespace().take(8).collect::<ArrayVec<_, 64>>();
|
||||
|
||||
join_to_arraystring(&split, &mut buf)?;
|
||||
let color_type = *(nummap::COLOR_TYPE_NUMMAP.get(&buf).ok_or_else(|| InvalidSizeError(color_type.to_string()))?);
|
||||
let color_type = nummap::get_color_type(&buf)?;
|
||||
|
||||
Ok(color_type)
|
||||
}
|
||||
|
|
2539
src/nummap.rs
2539
src/nummap.rs
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue