Skip to content

Commit 51ddac3

Browse files
authored
Merge pull request rust-lang#3096 from otavio/use-bytecount-count
utils: rewrite `count_newlines` using `bytecount::count`
2 parents a6ef302 + e203057 commit 51ddac3

File tree

4 files changed

+13
-2
lines changed

4 files changed

+13
-2
lines changed

Cargo.lock

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ rustc-ap-rustc_target = "272.0.0"
5151
rustc-ap-syntax = "272.0.0"
5252
rustc-ap-syntax_pos = "272.0.0"
5353
failure = "0.1.1"
54+
bytecount = { version = "0.3", features = ["simd-accel"] }
5455

5556
[dev-dependencies]
5657
assert_cli = "0.6"

src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#[macro_use]
1818
extern crate derive_new;
1919
extern crate atty;
20+
extern crate bytecount;
2021
extern crate diff;
2122
extern crate failure;
2223
extern crate itertools;

src/utils.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
use std::borrow::Cow;
1212

13+
use bytecount;
14+
1315
use rustc_target::spec::abi;
1416
use syntax::ast::{
1517
self, Attribute, CrateSugar, MetaItem, MetaItemKind, NestedMetaItem, NestedMetaItemKind, Path,
@@ -305,8 +307,8 @@ pub fn stmt_expr(stmt: &ast::Stmt) -> Option<&ast::Expr> {
305307

306308
#[inline]
307309
pub fn count_newlines(input: &str) -> usize {
308-
// Using `as_bytes` to omit UTF-8 decoding
309-
input.as_bytes().iter().filter(|&&c| c == b'\n').count()
310+
// Using bytes to omit UTF-8 decoding
311+
bytecount::count(input.as_bytes(), b'\n')
310312
}
311313

312314
// For format_missing and last_pos, need to use the source callsite (if applicable).

0 commit comments

Comments
 (0)