Skip to content

Commit 15897e9

Browse files
committed
feat: use bulk load to collect rendered spec line
1 parent c29e8fb commit 15897e9

File tree

1 file changed

+44
-51
lines changed

1 file changed

+44
-51
lines changed

src/py/mod.rs

Lines changed: 44 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -204,30 +204,18 @@ impl Flow {
204204
let spec = &self.0.flow.flow_instance;
205205
let mut sections: IndexMap<String, Vec<RenderedSpecLine>> = IndexMap::new();
206206

207-
// Initialize sections
208-
sections.insert(
209-
"Header".to_string(),
210-
vec![RenderedSpecLine {
211-
content: format!("Flow: {}", spec.name),
212-
scope: None,
213-
children: vec![],
214-
}],
215-
);
216-
for key in ["Sources", "Processing", "Targets", "Declarations"] {
217-
sections.insert(key.to_string(), Vec::new());
218-
}
219-
220207
// Sources
221-
for op in &spec.import_ops {
222-
sections
223-
.entry("Sources".to_string())
224-
.or_default()
225-
.push(RenderedSpecLine {
208+
sections.insert(
209+
"Source".to_string(),
210+
spec.import_ops
211+
.iter()
212+
.map(|op| RenderedSpecLine {
226213
content: format!("Import: name={}, {}", op.name, op.spec.format(mode)),
227214
scope: None,
228215
children: vec![],
229-
});
230-
}
216+
})
217+
.collect(),
218+
);
231219

232220
// Processing
233221
fn walk(
@@ -236,52 +224,57 @@ impl Flow {
236224
scope: Option<String>,
237225
) -> RenderedSpecLine {
238226
let content = format!("{}: {}", op.name, op.spec.format(mode));
239-
let mut line = RenderedSpecLine {
240-
content,
241-
scope,
242-
children: vec![],
227+
228+
let children = match &op.spec {
229+
ReactiveOpSpec::ForEach(fe) => fe
230+
.op_scope
231+
.ops
232+
.iter()
233+
.map(|nested| walk(nested, mode, Some(fe.op_scope.name.clone())))
234+
.collect(),
235+
_ => vec![],
243236
};
244237

245-
if let ReactiveOpSpec::ForEach(fe) = &op.spec {
246-
for nested in &fe.op_scope.ops {
247-
line.children
248-
.push(walk(nested, mode, Some(fe.op_scope.name.clone())));
249-
}
238+
RenderedSpecLine {
239+
content,
240+
scope,
241+
children,
250242
}
251-
252-
line
253243
}
254244

255-
for op in &spec.reactive_ops {
256-
sections
257-
.entry("Processing".to_string())
258-
.or_default()
259-
.push(walk(op, mode, None));
260-
}
245+
sections.insert(
246+
"Processing".to_string(),
247+
spec.reactive_ops
248+
.iter()
249+
.map(|op| walk(op, mode, None))
250+
.collect(),
251+
);
261252

262253
// Targets
263-
for op in &spec.export_ops {
264-
sections
265-
.entry("Targets".to_string())
266-
.or_default()
267-
.push(RenderedSpecLine {
254+
sections.insert(
255+
"Targets".to_string(),
256+
spec.export_ops
257+
.iter()
258+
.map(|op| RenderedSpecLine {
268259
content: format!("Export: name={}, {}", op.name, op.spec.format(mode)),
269260
scope: None,
270261
children: vec![],
271-
});
272-
}
262+
})
263+
.collect(),
264+
);
273265

274266
// Declarations
275-
for decl in &spec.declarations {
276-
sections
277-
.entry("Declarations".to_string())
278-
.or_default()
279-
.push(RenderedSpecLine {
267+
sections.insert(
268+
"Declarations".to_string(),
269+
spec.declarations
270+
.iter()
271+
.map(|decl| RenderedSpecLine {
280272
content: format!("Declaration: {}", decl.format(mode)),
281273
scope: None,
282274
children: vec![],
283-
});
284-
}
275+
})
276+
.collect(),
277+
);
285278

286279
Ok(RenderedSpec {
287280
sections: sections.into_iter().collect(),

0 commit comments

Comments
 (0)