summaryrefslogtreecommitdiff
path: root/src/exec
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2021-07-10 13:07:39 +0200
committerLaurenz <laurmaedje@gmail.com>2021-07-10 13:07:39 +0200
commit36b3067c19c8743032a44f888ee48702b88d135b (patch)
tree89893f4501109b35bb6498b93bda4f3cc82dba40 /src/exec
parent9950627789358b4d46c7fd8ba20d1428aee7bf01 (diff)
Eco string 🌱
Diffstat (limited to 'src/exec')
-rw-r--r--src/exec/context.rs5
-rw-r--r--src/exec/mod.rs15
2 files changed, 15 insertions, 5 deletions
diff --git a/src/exec/context.rs b/src/exec/context.rs
index 0f6d47f5..4764a808 100644
--- a/src/exec/context.rs
+++ b/src/exec/context.rs
@@ -3,6 +3,7 @@ use std::rc::Rc;
use super::{Exec, ExecWithMap, FontFamily, State};
use crate::diag::{Diag, DiagSet, Pass};
+use crate::eco::EcoString;
use crate::eval::{ExprMap, TemplateValue};
use crate::geom::{Align, Dir, Gen, GenAxis, Length, Linear, Sides, Size};
use crate::layout::{
@@ -77,7 +78,7 @@ impl ExecContext {
/// Push text into the active paragraph.
///
/// The text is split into lines at newlines.
- pub fn push_text(&mut self, text: impl Into<String>) {
+ pub fn push_text(&mut self, text: impl Into<EcoString>) {
self.stack.par.push(self.make_text_node(text));
}
@@ -143,7 +144,7 @@ impl ExecContext {
Pass::new(self.tree, self.diags)
}
- fn make_text_node(&self, text: impl Into<String>) -> ParChild {
+ fn make_text_node(&self, text: impl Into<EcoString>) -> ParChild {
ParChild::Text(
text.into(),
self.state.aligns.cross,
diff --git a/src/exec/mod.rs b/src/exec/mod.rs
index fc829676..2a145fbc 100644
--- a/src/exec/mod.rs
+++ b/src/exec/mod.rs
@@ -6,6 +6,7 @@ mod state;
pub use context::*;
pub use state::*;
+use std::fmt::Write;
use std::rc::Rc;
use crate::diag::Pass;
@@ -13,6 +14,7 @@ use crate::eval::{ExprMap, TemplateFunc, TemplateNode, TemplateValue, Value};
use crate::geom::{Dir, Gen};
use crate::layout::{LayoutTree, StackChild, StackNode};
use crate::pretty::pretty;
+use crate::eco::EcoString;
use crate::syntax::*;
/// Execute a template to produce a layout tree.
@@ -102,18 +104,25 @@ impl ExecWithMap for HeadingNode {
impl ExecWithMap for ListItem {
fn exec_with_map(&self, ctx: &mut ExecContext, map: &ExprMap) {
- exec_item(ctx, "•".to_string(), &self.body, map);
+ exec_item(ctx, '•'.into(), &self.body, map);
}
}
impl ExecWithMap for EnumItem {
fn exec_with_map(&self, ctx: &mut ExecContext, map: &ExprMap) {
- let label = self.number.unwrap_or(1).to_string() + ".";
+ let mut label = EcoString::new();
+ write!(&mut label, "{}", self.number.unwrap_or(1)).unwrap();
+ label.push('.');
exec_item(ctx, label, &self.body, map);
}
}
-fn exec_item(ctx: &mut ExecContext, label: String, body: &SyntaxTree, map: &ExprMap) {
+fn exec_item(
+ ctx: &mut ExecContext,
+ label: EcoString,
+ body: &SyntaxTree,
+ map: &ExprMap,
+) {
let label = ctx.exec_stack(|ctx| ctx.push_text(label));
let body = ctx.exec_tree_stack(body, map);
let stack = StackNode {