Skip to content

Commit 8bb500a

Browse files
committed
Auto merge of rust-lang#16395 - roife:internal/speed-up-LineEndings-with-memchr, r=Veykril
internal: speedup LineEndings calculation using 'memchr' See rust-lang/rust-analyzer#13538
2 parents 9d9b343 + 04ce4ce commit 8bb500a

File tree

3 files changed

+7
-4
lines changed

3 files changed

+7
-4
lines changed

Cargo.lock

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

crates/rust-analyzer/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ parser.workspace = true
6363
toolchain.workspace = true
6464
vfs-notify.workspace = true
6565
vfs.workspace = true
66+
memchr = "2.7.1"
6667

6768
[target.'cfg(windows)'.dependencies]
6869
winapi = "0.3.9"

crates/rust-analyzer/src/line_index.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
//! convert back to `\r\n` on the way out).
77
88
use ide_db::line_index::WideEncoding;
9+
use memchr::memmem;
910
use triomphe::Arc;
1011

1112
#[derive(Clone, Copy)]
@@ -39,10 +40,10 @@ impl LineEndings {
3940
let mut tail = buf.as_mut_slice();
4041
let mut crlf_seen = false;
4142

42-
let find_crlf = |src: &[u8]| src.windows(2).position(|it| it == b"\r\n");
43+
let finder = memmem::Finder::new(b"\r\n");
4344

4445
loop {
45-
let idx = match find_crlf(&tail[gap_len..]) {
46+
let idx = match finder.find(&tail[gap_len..]) {
4647
None if crlf_seen => tail.len(),
4748
// SAFETY: buf is unchanged and therefore still contains utf8 data
4849
None => return (unsafe { String::from_utf8_unchecked(buf) }, LineEndings::Unix),

0 commit comments

Comments
 (0)