diff options
| author | Otavio Salvador <otavio@ossystems.com.br> | 2018-10-13 17:39:19 -0300 |
|---|---|---|
| committer | Otavio Salvador <otavio@ossystems.com.br> | 2018-10-14 18:27:35 -0300 |
| commit | e203057db055adc5a5367d35bcd5bd103a3a21e8 (patch) | |
| tree | f871f02f89c96234c2bb2a75f9de7a108e4f4ca2 /src | |
| parent | c4a8cdcdf1e4f574c80f04bc0c5b058c5a83b4f6 (diff) | |
utils: rewrite `count_newlines` using `bytecount::count`
This uses a optimized byte count and also makes use of SIMD instructions to optimize the processing of the byte arrays. Signed-off-by: Otavio Salvador <otavio@ossystems.com.br>
Diffstat (limited to 'src')
| -rw-r--r-- | src/lib.rs | 1 | ||||
| -rw-r--r-- | src/utils.rs | 6 |
2 files changed, 5 insertions, 2 deletions
diff --git a/src/lib.rs b/src/lib.rs index 267096d9943..772ed8cb141 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -17,6 +17,7 @@ #[macro_use] extern crate derive_new; extern crate atty; +extern crate bytecount; extern crate diff; extern crate failure; extern crate itertools; diff --git a/src/utils.rs b/src/utils.rs index 63b238a7817..7ef9254a482 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -10,6 +10,8 @@ use std::borrow::Cow; +use bytecount; + use rustc_target::spec::abi; use syntax::ast::{ self, Attribute, CrateSugar, MetaItem, MetaItemKind, NestedMetaItem, NestedMetaItemKind, Path, @@ -305,8 +307,8 @@ pub fn stmt_expr(stmt: &ast::Stmt) -> Option<&ast::Expr> { #[inline] pub fn count_newlines(input: &str) -> usize { - // Using `as_bytes` to omit UTF-8 decoding - input.as_bytes().iter().filter(|&&c| c == b'\n').count() + // Using bytes to omit UTF-8 decoding + bytecount::count(input.as_bytes(), b'\n') } // For format_missing and last_pos, need to use the source callsite (if applicable). |
