Skip to content

Commit 908d451

Browse files
committed
perf: no need for pos_new
1 parent 3cd9911 commit 908d451

File tree

3 files changed

+15
-21
lines changed

3 files changed

+15
-21
lines changed

buildkite.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ steps:
8989
- cargo clippy
9090

9191
- label: flake check
92+
if: build.branch != "main"
9293
command:
9394
- echo +++
9495
- nix flake check

src/alejandra_engine/src/builder.rs

+13-20
Original file line numberDiff line numberDiff line change
@@ -13,27 +13,26 @@ pub(crate) enum Step {
1313

1414
#[derive(Clone)]
1515
pub(crate) struct BuildCtx {
16-
pub force_wide: bool,
17-
pub indentation: usize,
18-
pub pos_new: crate::position::Position,
19-
pub pos_old: crate::position::Position,
20-
pub path: String,
21-
pub vertical: bool,
16+
pub force_wide: bool,
17+
pub force_wide_success: bool,
18+
pub indentation: usize,
19+
pub pos_old: crate::position::Position,
20+
pub path: String,
21+
pub vertical: bool,
2222
}
2323

2424
impl BuildCtx {
2525
pub fn new(
2626
force_wide: bool,
2727
path: String,
28-
pos_new: crate::position::Position,
2928
pos_old: crate::position::Position,
3029
vertical: bool,
3130
) -> BuildCtx {
3231
BuildCtx {
3332
force_wide,
33+
force_wide_success: true,
3434
indentation: 0,
3535
path,
36-
pos_new,
3736
pos_old,
3837
vertical,
3938
}
@@ -51,7 +50,6 @@ pub(crate) fn build(
5150
force_wide,
5251
path,
5352
crate::position::Position::default(),
54-
crate::position::Position::default(),
5553
vertical,
5654
);
5755

@@ -61,8 +59,8 @@ pub(crate) fn build(
6159
&crate::builder::Step::Format(element),
6260
);
6361

64-
if build_ctx.force_wide && build_ctx.pos_new.line > 1 {
65-
None
62+
if force_wide {
63+
if build_ctx.force_wide_success { Some(builder.finish()) } else { None }
6664
} else {
6765
Some(builder.finish())
6866
}
@@ -74,7 +72,7 @@ fn build_step(
7472

7573
step: &crate::builder::Step,
7674
) {
77-
if build_ctx.force_wide && build_ctx.pos_new.line > 1 {
75+
if build_ctx.force_wide && !build_ctx.force_wide_success {
7876
return;
7977
}
8078

@@ -120,6 +118,8 @@ fn build_step(
120118
build_ctx.indentation += 1;
121119
}
122120
crate::builder::Step::NewLine => {
121+
build_ctx.force_wide_success = false;
122+
123123
add_token(
124124
builder,
125125
build_ctx,
@@ -158,7 +158,6 @@ fn add_token(
158158
text: &str,
159159
) {
160160
builder.token(rowan::SyntaxKind(kind as u16), text);
161-
build_ctx.pos_new.update(text);
162161
}
163162

164163
fn format(
@@ -283,13 +282,7 @@ pub(crate) fn fits_in_single_line(
283282
build_ctx: &crate::builder::BuildCtx,
284283
element: rnix::SyntaxElement,
285284
) -> bool {
286-
let line = build_ctx.pos_new.line;
287-
let maybe_green_node = build(element, true, build_ctx.path.clone(), false);
288-
289-
match maybe_green_node {
290-
Some(_) => build_ctx.pos_new.line == line,
291-
None => false,
292-
}
285+
build(element, true, build_ctx.path.clone(), false).is_some()
293286
}
294287

295288
pub(crate) fn make_isolated_token(

src/alejandra_engine/src/rules/lambda.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ pub(crate) fn rule(
7575
| rnix::SyntaxKind::NODE_LET_IN
7676
| rnix::SyntaxKind::NODE_LIST
7777
| rnix::SyntaxKind::NODE_STRING
78-
) && build_ctx.pos_new.column > 1;
78+
) && build_ctx.indentation > 0;
7979

8080
if should_indent {
8181
steps.push_back(crate::builder::Step::Indent);

0 commit comments

Comments
 (0)