Skip to content

Commit d0bbd78

Browse files
MahadMuhammadCohenArthur
authored andcommitted
refactor: compiling regex outside loop
1 parent 86e4d8a commit d0bbd78

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/transform.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ pub fn transform_code(code: &str, stderr_file: Option<&str>) -> Result<String> {
1717
let mut new_code = String::new();
1818
let additional_options = parse_additional_options(code);
1919

20+
// regular expression to capture the error with revision directive
21+
let captures_regex = regex!(r"//(?:\[(?P<revs>[\w\-,]+)])?~(?P<adjust>\||\^*)");
22+
2023
let mut line_num = 1;
2124
// finding the respective line number and adding the error code
2225
for line in code.lines() {
@@ -49,7 +52,7 @@ pub fn transform_code(code: &str, stderr_file: Option<&str>) -> Result<String> {
4952
new_line = format!("{}", error);
5053
} else {
5154
// For the error on the same line, we need to add error message at the end of the line
52-
let captures = regex!(r"//(?:\[(?P<revs>[\w\-,]+)])?~(?P<adjust>\||\^*)")
55+
let captures = captures_regex
5356
.captures(line)
5457
.expect("Could not find the error directive");
5558

0 commit comments

Comments
 (0)