Skip to content

Commit

Permalink
refactor: fix clippy warnings (String::as_bytes) (#1576)
Browse files Browse the repository at this point in the history
  • Loading branch information
greenhat authored Nov 15, 2024
1 parent c61f099 commit b13ed4d
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion assembly/src/library/namespace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ impl LibraryNamespace {
if matches!(source, Self::KERNEL_PATH | Self::EXEC_PATH | Self::ANON_PATH) {
return Ok(());
}
if source.as_bytes().len() > Self::MAX_LENGTH {
if source.len() > Self::MAX_LENGTH {
return Err(LibraryNamespaceError::Length);
}
if !source.starts_with(|c: char| c.is_ascii_lowercase() && c.is_ascii_alphabetic()) {
Expand Down
4 changes: 2 additions & 2 deletions assembly/src/library/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,8 @@ impl LibraryPath {

/// Return the size in bytes of this path when displayed as a string
pub fn byte_len(&self) -> usize {
self.inner.components.iter().map(|c| c.as_bytes().len()).sum::<usize>()
+ self.inner.ns.as_str().as_bytes().len()
self.inner.components.iter().map(|c| c.len()).sum::<usize>()
+ self.inner.ns.as_str().len()
+ (self.inner.components.len() * 2)
}

Expand Down
2 changes: 1 addition & 1 deletion assembly/src/parser/scanner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ pub struct Scanner<'input> {
impl<'input> Scanner<'input> {
/// Construct a new [Scanner] for the given `source`.
pub fn new(input: &'input str) -> Self {
let end = input.as_bytes().len();
let end = input.len();
assert!(end < u32::MAX as usize, "file too large");

let mut chars = input.char_indices().peekable();
Expand Down
2 changes: 1 addition & 1 deletion assembly/src/parser/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -860,7 +860,7 @@ impl<'input> Token<'input> {
// No match, it's an ident
None => Token::Ident(s),
// If the match is not exact, it's an ident
Some(matched) if matched.len() != s.as_bytes().len() => Token::Ident(s),
Some(matched) if matched.len() != s.len() => Token::Ident(s),
// Otherwise clone the Token corresponding to the keyword that was matched
Some(matched) => Self::KEYWORDS[matched.pattern().as_usize()].1.clone(),
}
Expand Down

0 comments on commit b13ed4d

Please sign in to comment.