diff --git a/benches/oneshot.rs b/benches/oneshot.rs index 5dbf993fe..9bce185c0 100644 --- a/benches/oneshot.rs +++ b/benches/oneshot.rs @@ -5,7 +5,7 @@ use iai::{black_box, main, Iai}; use typst::loading::MemLoader; use typst::parse::{parse, Scanner, TokenMode, Tokens}; use typst::source::SourceId; -use typst::{Context, Vm}; +use typst::Context; const SRC: &str = include_str!("bench.typ"); const FONT: &[u8] = include_bytes!("../fonts/IBMPlexSans-Regular.ttf"); @@ -26,7 +26,6 @@ main!( bench_eval, bench_layout, bench_highlight, - bench_byte_to_utf16, bench_render, ); @@ -67,37 +66,21 @@ fn bench_edit(iai: &mut Iai) { iai.run(|| black_box(ctx.sources.edit(id, 1168 .. 1171, "_Uhr_"))); } -fn bench_eval(iai: &mut Iai) { - let (mut ctx, id) = context(); - let mut vm = Vm::new(&mut ctx); - iai.run(|| vm.evaluate(id).unwrap()); -} - -fn bench_layout(iai: &mut Iai) { - let (mut ctx, id) = context(); - let mut vm = Vm::new(&mut ctx); - let module = vm.evaluate(id).unwrap(); - iai.run(|| module.template.layout_pages(&mut vm)); -} - fn bench_highlight(iai: &mut Iai) { let (ctx, id) = context(); let source = ctx.sources.get(id); iai.run(|| source.highlight(0 .. source.len_bytes(), |_, _| {})); } -fn bench_byte_to_utf16(iai: &mut Iai) { - let (ctx, id) = context(); - let source = ctx.sources.get(id); - let mut ranges = vec![]; - source.highlight(0 .. source.len_bytes(), |range, _| ranges.push(range)); - iai.run(|| { - ranges - .iter() - .map(|range| source.byte_to_utf16(range.start) - .. source.byte_to_utf16(range.end)) - .collect::>() - }); +fn bench_eval(iai: &mut Iai) { + let (mut ctx, id) = context(); + iai.run(|| ctx.evaluate(id).unwrap()); +} + +fn bench_layout(iai: &mut Iai) { + let (mut ctx, id) = context(); + let module = ctx.evaluate(id).unwrap(); + iai.run(|| module.template.layout(&mut ctx)); } fn bench_render(iai: &mut Iai) { diff --git a/src/eval/class.rs b/src/eval/class.rs index 5601fb0b6..5e1857d7b 100644 --- a/src/eval/class.rs +++ b/src/eval/class.rs @@ -2,8 +2,9 @@ use std::any::TypeId; use std::fmt::{self, Debug, Formatter, Write}; use std::hash::{Hash, Hasher}; -use super::{Args, Func, StyleMap, Template, Value, Vm}; +use super::{Args, Func, StyleMap, Template, Value}; use crate::diag::TypResult; +use crate::Context; /// A class of nodes. /// @@ -38,7 +39,7 @@ use crate::diag::TypResult; pub struct Class { name: &'static str, id: TypeId, - construct: fn(&mut Vm, &mut Args) -> TypResult, + construct: fn(&mut Context, &mut Args) -> TypResult, set: fn(&mut Args, &mut StyleMap) -> TypResult<()>, } @@ -81,8 +82,8 @@ impl Class { /// This parses both property and data arguments (in this order), styles the /// template constructed from the data with the style properties and wraps /// it in a value. - pub fn construct(&self, vm: &mut Vm, mut args: Args) -> TypResult { - let value = (self.construct)(vm, &mut args)?; + pub fn construct(&self, ctx: &mut Context, mut args: Args) -> TypResult { + let value = (self.construct)(ctx, &mut args)?; args.finish()?; Ok(value) } @@ -125,7 +126,7 @@ pub trait Construct { /// /// This is passed only the arguments that remain after execution of the /// class's set rule. - fn construct(vm: &mut Vm, args: &mut Args) -> TypResult