Skip to content

Commit

Permalink
rm unwrap
Browse files Browse the repository at this point in the history
  • Loading branch information
robertbastian committed Sep 25, 2024
1 parent 2cd552e commit 5be70f2
Showing 1 changed file with 15 additions and 16 deletions.
31 changes: 15 additions & 16 deletions components/properties/src/names.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ fn get_strict_u16(payload: &PropertyValueNameToEnumMapV1<'_>, name: &str) -> Opt

/// Avoid monomorphizing multiple copies of this function
fn get_loose_u16(payload: &PropertyValueNameToEnumMapV1<'_>, name: &str) -> Option<u16> {
fn recurse(mut cursor: ZeroTrieSimpleAsciiCursor, name: &[u8]) -> Option<usize> {
fn recurse(mut cursor: ZeroTrieSimpleAsciiCursor, mut rest: &[u8]) -> Option<usize> {
if cursor.is_empty() {
return None;
}
Expand All @@ -271,25 +271,24 @@ fn get_loose_u16(payload: &PropertyValueNameToEnumMapV1<'_>, name: &str) -> Opti
for skip in [b'\t', b'\n', b'\x0C', b'\r', b' ', 0x0B, b'_', b'-'] {
let mut skip_cursor = cursor.clone();
skip_cursor.step(skip);
if let Some(r) = recurse(skip_cursor, name) {
if let Some(r) = recurse(skip_cursor, rest) {
return Some(r);
}
}

// Skip whitespace, underscore, hyphen in input
#[allow(clippy::indexing_slicing)] // valid index
let name = &name[name
.iter()
.position(|&ascii| {
!matches!(
ascii,
b'\t' | b'\n' | b'\x0C' | b'\r' | b' ' | 0x0B | b'_' | b'-'
)
})
.unwrap_or(name.len())..];

let Some((&ascii, rest)) = name.split_first() else {
return cursor.take_value();
let ascii = loop {
let Some((&a, r)) = rest.split_first() else {
return cursor.take_value();
};
rest = r;

// Skip whitespace, underscore, hyphen in input
if !matches!(
a,
b'\t' | b'\n' | b'\x0C' | b'\r' | b' ' | 0x0B | b'_' | b'-'
) {
break a;
}
};

let mut other_case_cursor = cursor.clone();
Expand Down

0 comments on commit 5be70f2

Please sign in to comment.