Skip to content

Use memchr for split_into_lines #73

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Boshen opened this issue Nov 28, 2023 · 0 comments · Fixed by #82
Closed

Use memchr for split_into_lines #73

Boshen opened this issue Nov 28, 2023 · 0 comments · Fixed by #82

Comments

@Boshen
Copy link
Contributor

Boshen commented Nov 28, 2023

// /[^\n]+\n?|\n/g
pub fn split_into_lines(source: &str) -> Vec<&str> {
let mut results = Vec::new();
let mut i = 0;
let bytes = source.as_bytes();
while i < bytes.len() {
let cc = bytes[i];
if cc == 10 {
results.push("\n");
i += 1;
} else {
let mut j = i + 1;
while j < bytes.len() && bytes[j] != 10 {
j += 1;
}
results.push(&source[i..(j + 1).min(bytes.len())]);
i = j + 1;
}
}
results
}

You may copy this version:

https://github.com/rust-lang/cargo/blob/30efe860c0e4adc1a6d7057ad223dc6e47d34edf/src/cargo/sources/registry/index.rs#L1048-L1072


p.s. It seems like split_into_lines is called multiples in different places, I can't tell if the call is cached or not.

Boshen added a commit that referenced this issue Dec 1, 2023
@Boshen Boshen closed this as completed in #82 Dec 1, 2023
Boshen added a commit that referenced this issue Dec 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant