Skip to content
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

fix: fix performance regression on resolver::parse_doc_string #619

Merged
merged 1 commit into from
Jul 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 46 additions & 2 deletions kclvm/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions kclvm/sema/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ compiler_base_span = {path = "../../compiler_base/span", version = "0.0.2"}
compiler_base_session = {path = "../../compiler_base/session"}
compiler_base_macros = "0.0.1"
compiler_base_error = "0.0.8"
lazy_static = "1.4.0"
pcre2 = "*"

[dev-dependencies]
kclvm-parser = {path = "../parser"}
Expand Down
25 changes: 15 additions & 10 deletions kclvm/sema/src/resolver/doc.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
use regex::Regex;
use pcre2::bytes::Regex;
use std::collections::HashSet;
use std::iter::Iterator;
use std::str;

lazy_static::lazy_static! {
static ref RE: Regex = Regex::new(r#"(?s)^(['\"]{3})(.*?)(['\"]{3})$"#).unwrap();
}

/// strip leading and trailing triple quotes from the original docstring content
fn strip_quotes(original: &mut String) {
let quote = original.chars().next().unwrap();
let pattern = format!("(?s)^{char}{{3}}(.*?){char}{{3}}$", char = quote);
let re = Regex::new(&pattern).unwrap();
let caps = re.captures(&original);
let result = match caps {
Some(caps) => caps,
None => return,
};
let content = result[1].to_owned();
*original = content;
if quote != '"' && quote != '\'' {
return;
}
if let Ok(Some(mat)) = RE.find(original.as_bytes()) {
let content = str::from_utf8(&original.as_bytes()[mat.start() + 3..mat.end() - 3])
.unwrap()
.to_owned();
*original = content;
}
}

fn expand_tabs(s: &str, spaces_per_tab: usize) -> String {
Expand Down
Loading