mirror of
https://github.com/RGBCube/alejandra
synced 2025-07-31 04:27:45 +00:00
perf: control recursion depth
This commit is contained in:
parent
6692b4ae85
commit
33cb45569d
2 changed files with 21 additions and 8 deletions
|
@ -16,13 +16,14 @@ pub(crate) enum Step {
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub(crate) struct BuildCtx {
|
pub(crate) struct BuildCtx {
|
||||||
pub config: Config,
|
pub config: Config,
|
||||||
pub force_wide: bool,
|
pub fitting_in_single_line_depth: usize,
|
||||||
pub force_wide_success: bool,
|
pub force_wide: bool,
|
||||||
pub indentation: usize,
|
pub force_wide_success: bool,
|
||||||
pub pos_old: crate::position::Position,
|
pub indentation: usize,
|
||||||
pub path: String,
|
pub pos_old: crate::position::Position,
|
||||||
pub vertical: bool,
|
pub path: String,
|
||||||
|
pub vertical: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn build(
|
pub(crate) fn build(
|
||||||
|
@ -262,6 +263,7 @@ fn format_wider(
|
||||||
match element {
|
match element {
|
||||||
rnix::SyntaxElement::Node(node) => {
|
rnix::SyntaxElement::Node(node) => {
|
||||||
let mut build_ctx_clone = build_ctx.clone();
|
let mut build_ctx_clone = build_ctx.clone();
|
||||||
|
|
||||||
build_ctx_clone.vertical =
|
build_ctx_clone.vertical =
|
||||||
!fits_in_single_line(build_ctx, node.clone().into());
|
!fits_in_single_line(build_ctx, node.clone().into());
|
||||||
|
|
||||||
|
@ -284,7 +286,17 @@ pub(crate) fn fits_in_single_line(
|
||||||
..build_ctx_old.clone()
|
..build_ctx_old.clone()
|
||||||
};
|
};
|
||||||
|
|
||||||
build(&mut build_ctx, element).is_some()
|
build_ctx.fitting_in_single_line_depth += 1;
|
||||||
|
|
||||||
|
if build_ctx.fitting_in_single_line_depth >= 2 {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
let fits = build(&mut build_ctx, element).is_some();
|
||||||
|
|
||||||
|
build_ctx.fitting_in_single_line_depth -= 1;
|
||||||
|
|
||||||
|
fits
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn make_isolated_token(
|
pub(crate) fn make_isolated_token(
|
||||||
|
|
|
@ -33,6 +33,7 @@ pub fn in_memory(
|
||||||
|
|
||||||
let mut build_ctx = crate::builder::BuildCtx {
|
let mut build_ctx = crate::builder::BuildCtx {
|
||||||
config,
|
config,
|
||||||
|
fitting_in_single_line_depth: 0,
|
||||||
force_wide: false,
|
force_wide: false,
|
||||||
force_wide_success: true,
|
force_wide_success: true,
|
||||||
indentation: 0,
|
indentation: 0,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue