Use string slices as function arguments
Also use the same names as parameters.
This commit is contained in:
parent
eadd7b1081
commit
de9aae1e82
|
@ -7,11 +7,11 @@ use rayon::prelude::*;
|
||||||
|
|
||||||
/// Searches for the word, parallelized by rayon
|
/// Searches for the word, parallelized by rayon
|
||||||
#[pyfunction]
|
#[pyfunction]
|
||||||
fn search(py: Python<'_>, contents: &str, search: String) -> PyResult<usize> {
|
fn search(py: Python<'_>, contents: &str, needle: &str) -> PyResult<usize> {
|
||||||
let count = py.allow_threads(move || {
|
let count = py.allow_threads(move || {
|
||||||
contents
|
contents
|
||||||
.par_lines()
|
.par_lines()
|
||||||
.map(|line| count_line(line, &search))
|
.map(|line| count_line(line, needle))
|
||||||
.sum()
|
.sum()
|
||||||
});
|
});
|
||||||
Ok(count)
|
Ok(count)
|
||||||
|
@ -19,8 +19,8 @@ fn search(py: Python<'_>, contents: &str, search: String) -> PyResult<usize> {
|
||||||
|
|
||||||
/// Searches for a word in a classic sequential fashion
|
/// Searches for a word in a classic sequential fashion
|
||||||
#[pyfunction]
|
#[pyfunction]
|
||||||
fn search_sequential(contents: &str, needle: String) -> PyResult<usize> {
|
fn search_sequential(contents: &str, needle: &str) -> PyResult<usize> {
|
||||||
let result = contents.lines().map(|line| count_line(line, &needle)).sum();
|
let result = contents.lines().map(|line| count_line(line, needle)).sum();
|
||||||
Ok(result)
|
Ok(result)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue