mirror of
https://github.com/RGBCube/alejandra
synced 2025-07-31 12:37:45 +00:00
perf: lazy position
This commit is contained in:
parent
d9f5fe5022
commit
ea3418cbe7
2 changed files with 38 additions and 16 deletions
|
@ -2,23 +2,29 @@
|
||||||
rnix = "*"
|
rnix = "*"
|
||||||
rowan = "0.12.6" # follows rnix
|
rowan = "0.12.6" # follows rnix
|
||||||
|
|
||||||
[target.aarch64-unknown-linux-musl.dependencies]
|
[target.aarch64-unknown-linux-musl.dependencies.mimalloc]
|
||||||
mimalloc = { version = "*", default-features = false }
|
default-features = false
|
||||||
|
version = "*"
|
||||||
|
|
||||||
[target.armv6l-unknown-linux-musleabihf.dependencies]
|
[target.armv6l-unknown-linux-musleabihf.dependencies.mimalloc]
|
||||||
mimalloc = { version = "*", default-features = false }
|
default-features = false
|
||||||
|
version = "*"
|
||||||
|
|
||||||
[target.armv7l-unknown-linux-musleabihf.dependencies]
|
[target.armv7l-unknown-linux-musleabihf.dependencies.mimalloc]
|
||||||
mimalloc = { version = "*", default-features = false }
|
default-features = false
|
||||||
|
version = "*"
|
||||||
|
|
||||||
[target.i686-unknown-linux-musl.dependencies]
|
[target.i686-unknown-linux-musl.dependencies.mimalloc]
|
||||||
mimalloc = { version = "*", default-features = false }
|
default-features = false
|
||||||
|
version = "*"
|
||||||
|
|
||||||
[target.x86_64-unknown-linux-gnu.dependencies]
|
[target.x86_64-unknown-linux-gnu.dependencies.mimalloc]
|
||||||
mimalloc = { version = "*", default-features = false }
|
default-features = false
|
||||||
|
version = "*"
|
||||||
|
|
||||||
[target.x86_64-unknown-linux-musl.dependencies]
|
[target.x86_64-unknown-linux-musl.dependencies.mimalloc]
|
||||||
mimalloc = { version = "*", default-features = false }
|
default-features = false
|
||||||
|
version = "*"
|
||||||
|
|
||||||
[package]
|
[package]
|
||||||
authors = ["Kevin Amado <kamadorueda@gmail.com>"]
|
authors = ["Kevin Amado <kamadorueda@gmail.com>"]
|
||||||
|
|
|
@ -15,13 +15,24 @@ impl Children {
|
||||||
) -> Children {
|
) -> Children {
|
||||||
let mut children: Vec<rnix::SyntaxElement> = Vec::new();
|
let mut children: Vec<rnix::SyntaxElement> = Vec::new();
|
||||||
|
|
||||||
let mut pos = build_ctx.pos_old.clone();
|
// Updating the position is costly,
|
||||||
|
// so let's just do it when really needed
|
||||||
|
let mut pos = {
|
||||||
|
let has_comments = node.children_with_tokens().any(|child| {
|
||||||
|
matches!(child.kind(), rnix::SyntaxKind::TOKEN_COMMENT)
|
||||||
|
});
|
||||||
|
|
||||||
|
if has_comments { Some(build_ctx.pos_old.clone()) } else { None }
|
||||||
|
};
|
||||||
|
|
||||||
for child in node.children_with_tokens() {
|
for child in node.children_with_tokens() {
|
||||||
match child {
|
match child {
|
||||||
rnix::SyntaxElement::Node(node) => {
|
rnix::SyntaxElement::Node(node) => {
|
||||||
children.push(node.clone().into());
|
children.push(node.clone().into());
|
||||||
pos.update(&node.text().to_string());
|
|
||||||
|
if pos.is_some() {
|
||||||
|
pos.as_mut().unwrap().update(&node.text().to_string());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
rnix::SyntaxElement::Token(token) => {
|
rnix::SyntaxElement::Token(token) => {
|
||||||
match token.kind() {
|
match token.kind() {
|
||||||
|
@ -29,7 +40,10 @@ impl Children {
|
||||||
children.push(
|
children.push(
|
||||||
crate::builder::make_isolated_token(
|
crate::builder::make_isolated_token(
|
||||||
rnix::SyntaxKind::TOKEN_COMMENT,
|
rnix::SyntaxKind::TOKEN_COMMENT,
|
||||||
&dedent_comment(&pos, token.text()),
|
&dedent_comment(
|
||||||
|
&pos.as_ref().unwrap(),
|
||||||
|
token.text(),
|
||||||
|
),
|
||||||
)
|
)
|
||||||
.into(),
|
.into(),
|
||||||
);
|
);
|
||||||
|
@ -44,7 +58,9 @@ impl Children {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pos.update(token.text());
|
if pos.is_some() {
|
||||||
|
pos.as_mut().unwrap().update(token.text());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue