Skip to content

Commit ad04638

Browse files
authored
perf: reduce memory usage (#13)
1 parent 575828c commit ad04638

File tree

3 files changed

+72
-13
lines changed

3 files changed

+72
-13
lines changed

Cargo.lock

Lines changed: 60 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ tracing = ["dprint-core/tracing"]
2626

2727
[dependencies]
2828
anyhow = "1.0.65"
29-
dprint-core = { version = "0.65.0", features = ["formatting"] }
29+
dprint-core = { version = "0.66.1", features = ["formatting"] }
30+
dprint-core-macros = "0.1.0"
3031
itertools = "0.10"
3132
serde = { version = "1.0.145", features = ["derive"] }
3233
serde_json = { version = "1.0", optional = true }

src/generation/generate.rs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
use dprint_core::formatting::conditions::*;
44
use dprint_core::formatting::ir_helpers::SingleLineOptions;
55
use dprint_core::formatting::*;
6+
use dprint_core_macros::sc;
67
use std::cell::Cell;
78
use std::rc::Rc;
89
use taplo::rowan::NodeOrToken;
@@ -64,7 +65,7 @@ fn gen_node_with_inner<'a>(node: SyntaxElement, context: &mut Context<'a>, inner
6465
SyntaxKind::COMMENT => Ok(gen_comment(token, context)),
6566
SyntaxKind::MULTI_LINE_STRING | SyntaxKind::MULTI_LINE_STRING_LITERAL => {
6667
let mut items = PrintItems::new();
67-
items.push_str("");
68+
items.push_force_current_line_indentation();
6869
items.extend(ir_helpers::gen_from_raw_string(token.text().trim()));
6970
Ok(items)
7071
}
@@ -178,14 +179,14 @@ fn gen_inline_table<'a>(node: SyntaxNode, context: &mut Context<'a>) -> PrintIte
178179
ensure_all_kind(values.clone(), SyntaxKind::ENTRY)?;
179180

180181
let mut items = PrintItems::new();
181-
items.push_str("{");
182+
items.push_sc(sc!("{"));
182183
let mut had_item = false;
183184
for (i, value) in values.enumerate() {
184-
items.push_str(if i > 0 { ", " } else { " " });
185+
items.push_sc(if i > 0 { sc!(", ") } else { sc!(" ") });
185186
items.extend(gen_node(value.into(), context));
186187
had_item = true;
187188
}
188-
items.push_str(if had_item { " }" } else { "}" });
189+
items.push_sc(if had_item { sc!(" }") } else { sc!("}") });
189190

190191
// the comment seems to be stored as the last child of an inline table, so check for it here
191192
if let Some(NodeOrToken::Token(token)) = node.children_with_tokens().last() {
@@ -209,7 +210,7 @@ fn gen_entry<'a>(node: SyntaxNode, context: &mut Context<'a>) -> PrintItemsResul
209210
let mut items = PrintItems::new();
210211

211212
items.extend(gen_node(key.into(), context));
212-
items.push_str(" = ");
213+
items.push_sc(sc!(" = "));
213214
items.extend(gen_node(value.into(), context));
214215

215216
Ok(items)
@@ -237,19 +238,19 @@ fn gen_table_header<'a>(node: SyntaxNode, context: &mut Context<'a>) -> PrintIte
237238
// Spec: Naming rules for tables are the same as for keys
238239
let key = get_child_with_kind(node.clone(), SyntaxKind::KEY)?;
239240
let mut items = PrintItems::new();
240-
items.push_str("[");
241+
items.push_sc(sc!("["));
241242
items.extend(gen_node(key.into(), context));
242-
items.push_str("]");
243+
items.push_sc(sc!("]"));
243244
Ok(items)
244245
}
245246

246247
fn gen_table_array_header<'a>(node: SyntaxNode, context: &mut Context<'a>) -> PrintItemsResult {
247248
// Spec: Naming rules for tables are the same as for keys
248249
let key = get_child_with_kind(node.clone(), SyntaxKind::KEY)?;
249250
let mut items = PrintItems::new();
250-
items.push_str("[[");
251+
items.push_sc(sc!("[["));
251252
items.extend(gen_node(key.into(), context));
252-
items.push_str("]]");
253+
items.push_sc(sc!("]]"));
253254
Ok(items)
254255
}
255256

0 commit comments

Comments
 (0)