mirror of
https://github.com/rust-lang/rust.git
synced 2026-05-29 20:46:07 +03:00
Omit unnecessary UTF-8 decoding
This commit is contained in:
+2
-1
@@ -251,7 +251,8 @@ pub fn stmt_expr(stmt: &ast::Stmt) -> Option<&ast::Expr> {
|
||||
|
||||
#[inline]
|
||||
pub fn count_newlines(input: &str) -> usize {
|
||||
input.chars().filter(|&c| c == '\n').count()
|
||||
// Using `as_bytes` to omit UTF-8 decoding
|
||||
input.as_bytes().iter().filter(|&&c| c == b'\n').count()
|
||||
}
|
||||
|
||||
macro_rules! msg {
|
||||
|
||||
Reference in New Issue
Block a user