Skip to content

Commit ef67401

Browse files
committed
memoize codeowners
1 parent f708aa9 commit ef67401

File tree

3 files changed

+92
-8
lines changed

3 files changed

+92
-8
lines changed

Cargo.lock

+85-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ fast-glob = "0.4.0"
1818
ignore = "0.4.23"
1919
itertools = "0.14.0"
2020
lazy_static = "1.5.0"
21+
memoize = "0.5.1"
2122
path-clean = "1.0.1"
2223
rayon = "1.10.0"
2324
regex = "1.11.1"

src/ownership/parser.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use crate::ownership::{FileGenerator, TeamOwnership};
22
use fast_glob::glob_match;
3+
use memoize::memoize;
34
use std::{
45
error::Error,
56
fs,
@@ -17,7 +18,7 @@ pub fn team_name_from_file_path(file_path: &Path, codeowners_file_path: &PathBuf
1718
format!("/{}", file_path_str)
1819
};
1920

20-
let codeowners_lines_in_priorty = build_codeowners_lines_in_priority(codeowners_file_path)?;
21+
let codeowners_lines_in_priorty = build_codeowners_lines_in_priority(codeowners_file_path.to_string_lossy().into_owned());
2122

2223
for line in codeowners_lines_in_priorty {
2324
let (glob, team_name) = line
@@ -31,10 +32,11 @@ pub fn team_name_from_file_path(file_path: &Path, codeowners_file_path: &PathBuf
3132
Ok(None)
3233
}
3334

34-
fn build_codeowners_lines_in_priority(codeowners_file_path: &PathBuf) -> Result<Vec<String>, Box<dyn Error>> {
35-
let codeowners_file = fs::read_to_string(codeowners_file_path)?;
35+
#[memoize]
36+
fn build_codeowners_lines_in_priority(codeowners_file_path: String) -> Vec<String> {
37+
let codeowners_file = fs::read_to_string(codeowners_file_path).unwrap();
3638
let stripped_lines = stripped_lines_by_priority(&codeowners_file);
37-
Ok(stripped_lines)
39+
stripped_lines
3840
}
3941

4042
fn stripped_lines_by_priority(codeowners_file: &str) -> Vec<String> {

0 commit comments

Comments
 (0)