Skip to content

Commit

Permalink
str_latin1_up_to: Use unwrap_or_else to only call len when necessary
Browse files Browse the repository at this point in the history
  • Loading branch information
arnej authored and hsivonen committed Mar 15, 2021
1 parent f69ab46 commit e98a209
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/mem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2058,7 +2058,7 @@ pub fn utf8_latin1_up_to(buffer: &[u8]) -> usize {
/// Returns the index of first byte that starts a non-Latin1 byte
/// sequence, or the length of the string if there are none.
pub fn str_latin1_up_to(buffer: &str) -> usize {
is_str_latin1_impl(buffer).unwrap_or(buffer.len())
is_str_latin1_impl(buffer).unwrap_or_else(|| buffer.len())
}

/// Replaces unpaired surrogates in the input with the REPLACEMENT CHARACTER.
Expand Down

0 comments on commit e98a209

Please sign in to comment.