Skip to content

Commit 83c8d23

Browse files
committed
Omit unnecessary UTF-8 decoding
1 parent e5572bb commit 83c8d23

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src/utils.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,8 @@ pub fn stmt_expr(stmt: &ast::Stmt) -> Option<&ast::Expr> {
251251

252252
#[inline]
253253
pub fn count_newlines(input: &str) -> usize {
254-
input.chars().filter(|&c| c == '\n').count()
254+
// Using `as_bytes` to omit UTF-8 decoding
255+
input.as_bytes().iter().filter(|&&c| c == b'\n').count()
255256
}
256257

257258
macro_rules! msg {

0 commit comments

Comments
 (0)