mirror of
https://github.com/typst/typst
synced 2025-05-14 17:15:28 +08:00
Remove layout-cache feature
This commit is contained in:
parent
e01970b20a
commit
61d1e1a683
47
Cargo.lock
generated
47
Cargo.lock
generated
@ -581,12 +581,6 @@ dependencies = [
|
|||||||
"miniz_oxide 0.4.4",
|
"miniz_oxide 0.4.4",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "ppv-lite86"
|
|
||||||
version = "0.2.16"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "eb9f9e6e233e5c4a35559a617bf40a4ec447db2e84c20b55a6f83167b7e57872"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "proc-macro2"
|
name = "proc-macro2"
|
||||||
version = "1.0.36"
|
version = "1.0.36"
|
||||||
@ -605,46 +599,6 @@ dependencies = [
|
|||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "rand"
|
|
||||||
version = "0.8.4"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "2e7573632e6454cf6b99d7aac4ccca54be06da05aca2ef7423d22d27d4d4bcd8"
|
|
||||||
dependencies = [
|
|
||||||
"libc",
|
|
||||||
"rand_chacha",
|
|
||||||
"rand_core",
|
|
||||||
"rand_hc",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "rand_chacha"
|
|
||||||
version = "0.3.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88"
|
|
||||||
dependencies = [
|
|
||||||
"ppv-lite86",
|
|
||||||
"rand_core",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "rand_core"
|
|
||||||
version = "0.6.3"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "d34f1408f55294453790c48b2f1ebbb1c5b4b7563eb1f418bcfcfdbb06ebb4e7"
|
|
||||||
dependencies = [
|
|
||||||
"getrandom",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "rand_hc"
|
|
||||||
version = "0.3.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "d51e9f596de227fda2ea6c84607f5558e196eeaf43c986b724ba4fb8fdf497e7"
|
|
||||||
dependencies = [
|
|
||||||
"rand_core",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "rctree"
|
name = "rctree"
|
||||||
version = "0.4.0"
|
version = "0.4.0"
|
||||||
@ -958,7 +912,6 @@ dependencies = [
|
|||||||
"pdf-writer",
|
"pdf-writer",
|
||||||
"pico-args",
|
"pico-args",
|
||||||
"pixglyph",
|
"pixglyph",
|
||||||
"rand",
|
|
||||||
"resvg",
|
"resvg",
|
||||||
"roxmltree",
|
"roxmltree",
|
||||||
"rustybuzz",
|
"rustybuzz",
|
||||||
|
@ -5,10 +5,9 @@ authors = ["The Typst Project Developers"]
|
|||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = ["fs", "layout-cache"]
|
default = ["fs"]
|
||||||
cli = ["fs", "pico-args", "codespan-reporting", "same-file"]
|
cli = ["fs", "pico-args", "codespan-reporting", "same-file"]
|
||||||
fs = ["dirs", "memmap2", "same-file", "walkdir"]
|
fs = ["dirs", "memmap2", "same-file", "walkdir"]
|
||||||
layout-cache = []
|
|
||||||
|
|
||||||
# Dependency updates:
|
# Dependency updates:
|
||||||
# - Bump ttf-parser when rustybuzz is updated
|
# - Bump ttf-parser when rustybuzz is updated
|
||||||
@ -64,9 +63,6 @@ dirs = { version = "4", optional = true }
|
|||||||
memmap2 = { version = "0.5", optional = true }
|
memmap2 = { version = "0.5", optional = true }
|
||||||
walkdir = { version = "2", optional = true }
|
walkdir = { version = "2", optional = true }
|
||||||
|
|
||||||
# Still here for layout cache evaluation, but must be activated manually.
|
|
||||||
rand = { version = "0.8", optional = true }
|
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
filedescriptor = "0.8"
|
filedescriptor = "0.8"
|
||||||
iai = { git = "https://github.com/reknih/iai" }
|
iai = { git = "https://github.com/reknih/iai" }
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
use std::any::{Any, TypeId};
|
use std::any::{Any, TypeId};
|
||||||
use std::fmt::{self, Debug, Formatter};
|
use std::fmt::{self, Debug, Formatter};
|
||||||
use std::hash::{Hash, Hasher};
|
use std::hash::Hash;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use super::{StyleChain, Template};
|
use super::{StyleChain, Template};
|
||||||
@ -59,18 +59,12 @@ impl Debug for ShowNode {
|
|||||||
|
|
||||||
impl PartialEq for ShowNode {
|
impl PartialEq for ShowNode {
|
||||||
fn eq(&self, other: &Self) -> bool {
|
fn eq(&self, other: &Self) -> bool {
|
||||||
// We cast to thin pointers for comparison because we don't want to
|
self.0.eq(&other.0)
|
||||||
// compare vtables (which can be different across codegen units).
|
|
||||||
std::ptr::eq(
|
|
||||||
Arc::as_ptr(&self.0) as *const (),
|
|
||||||
Arc::as_ptr(&other.0) as *const (),
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
trait Bounds: Show + Debug + Sync + Send + 'static {
|
trait Bounds: Show + Debug + Sync + Send + 'static {
|
||||||
fn as_any(&self) -> &dyn Any;
|
fn as_any(&self) -> &dyn Any;
|
||||||
fn hash64(&self) -> u64;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T> Bounds for T
|
impl<T> Bounds for T
|
||||||
@ -80,19 +74,4 @@ where
|
|||||||
fn as_any(&self) -> &dyn Any {
|
fn as_any(&self) -> &dyn Any {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
fn hash64(&self) -> u64 {
|
|
||||||
// Also hash the TypeId since nodes with different types but
|
|
||||||
// equal data should be different.
|
|
||||||
let mut state = fxhash::FxHasher64::default();
|
|
||||||
self.type_id().hash(&mut state);
|
|
||||||
self.hash(&mut state);
|
|
||||||
state.finish()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Hash for dyn Bounds {
|
|
||||||
fn hash<H: Hasher>(&self, state: &mut H) {
|
|
||||||
state.write_u64(self.hash64());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -11,8 +11,6 @@ use crate::geom::Scalar;
|
|||||||
const TEMP_LEN: usize = 4;
|
const TEMP_LEN: usize = 4;
|
||||||
|
|
||||||
/// Caches layouting artifacts.
|
/// Caches layouting artifacts.
|
||||||
///
|
|
||||||
/// _This is only available when the `layout-cache` feature is enabled._
|
|
||||||
#[derive(Default, Clone)]
|
#[derive(Default, Clone)]
|
||||||
pub struct LayoutCache {
|
pub struct LayoutCache {
|
||||||
/// Maps from node hashes to the resulting frames and regions in which the
|
/// Maps from node hashes to the resulting frames and regions in which the
|
||||||
@ -150,14 +148,6 @@ impl LayoutCache {
|
|||||||
entries.retain(|f| f.hits() as f64 / f.age() as f64 > threshold);
|
entries.retain(|f| f.hits() as f64 / f.age() as f64 > threshold);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#[cfg(feature = "rand")]
|
|
||||||
EvictionPolicy::Random => {
|
|
||||||
// Fraction of items that should be kept.
|
|
||||||
let threshold = self.max_size as f64 / len as f64;
|
|
||||||
for entries in self.frames.values_mut() {
|
|
||||||
entries.retain(|_| rand::random::<f64>() > threshold);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
EvictionPolicy::Patterns => {
|
EvictionPolicy::Patterns => {
|
||||||
let kept = self.entries().filter(|f| f.properties().must_keep()).count();
|
let kept = self.entries().filter(|f| f.properties().must_keep()).count();
|
||||||
|
|
||||||
@ -188,8 +178,6 @@ impl LayoutCache {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Cached frames from past layouting.
|
/// Cached frames from past layouting.
|
||||||
///
|
|
||||||
/// _This is only available when the `layout-cache` feature is enabled._
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct FramesEntry {
|
pub struct FramesEntry {
|
||||||
/// The cached frames for a node.
|
/// The cached frames for a node.
|
||||||
@ -340,9 +328,6 @@ pub enum EvictionPolicy {
|
|||||||
LeastRecentlyUsed,
|
LeastRecentlyUsed,
|
||||||
/// Evict the least frequently used item.
|
/// Evict the least frequently used item.
|
||||||
LeastFrequentlyUsed,
|
LeastFrequentlyUsed,
|
||||||
/// Evict randomly.
|
|
||||||
#[cfg(feature = "rand")]
|
|
||||||
Random,
|
|
||||||
/// Use the pattern verdicts.
|
/// Use the pattern verdicts.
|
||||||
Patterns,
|
Patterns,
|
||||||
/// Do not evict.
|
/// Do not evict.
|
||||||
|
@ -1,12 +1,10 @@
|
|||||||
//! Layouting infrastructure.
|
//! Layouting infrastructure.
|
||||||
|
|
||||||
mod constraints;
|
mod constraints;
|
||||||
#[cfg(feature = "layout-cache")]
|
|
||||||
mod incremental;
|
mod incremental;
|
||||||
mod regions;
|
mod regions;
|
||||||
|
|
||||||
pub use constraints::*;
|
pub use constraints::*;
|
||||||
#[cfg(feature = "layout-cache")]
|
|
||||||
pub use incremental::*;
|
pub use incremental::*;
|
||||||
pub use regions::*;
|
pub use regions::*;
|
||||||
|
|
||||||
@ -141,10 +139,6 @@ impl Layout for LayoutNode {
|
|||||||
) -> TypResult<Vec<Constrained<Arc<Frame>>>> {
|
) -> TypResult<Vec<Constrained<Arc<Frame>>>> {
|
||||||
let styles = styles.barred(self.id());
|
let styles = styles.barred(self.id());
|
||||||
|
|
||||||
#[cfg(not(feature = "layout-cache"))]
|
|
||||||
return self.0.layout(ctx, regions, styles);
|
|
||||||
|
|
||||||
#[cfg(feature = "layout-cache")]
|
|
||||||
let hash = {
|
let hash = {
|
||||||
let mut state = fxhash::FxHasher64::default();
|
let mut state = fxhash::FxHasher64::default();
|
||||||
self.hash(&mut state);
|
self.hash(&mut state);
|
||||||
@ -154,7 +148,6 @@ impl Layout for LayoutNode {
|
|||||||
|
|
||||||
// This is not written with `unwrap_or_else`, because then the
|
// This is not written with `unwrap_or_else`, because then the
|
||||||
// #[track_caller] annotation doesn't work.
|
// #[track_caller] annotation doesn't work.
|
||||||
#[cfg(feature = "layout-cache")]
|
|
||||||
if let Some(frames) = vm.layout_cache.get(hash, regions) {
|
if let Some(frames) = vm.layout_cache.get(hash, regions) {
|
||||||
Ok(frames)
|
Ok(frames)
|
||||||
} else {
|
} else {
|
||||||
@ -199,18 +192,12 @@ impl Debug for LayoutNode {
|
|||||||
|
|
||||||
impl PartialEq for LayoutNode {
|
impl PartialEq for LayoutNode {
|
||||||
fn eq(&self, other: &Self) -> bool {
|
fn eq(&self, other: &Self) -> bool {
|
||||||
// We cast to thin pointers for comparison because we don't want to
|
self.0.eq(&other.0)
|
||||||
// compare vtables (which can be different across codegen units).
|
|
||||||
std::ptr::eq(
|
|
||||||
Arc::as_ptr(&self.0) as *const (),
|
|
||||||
Arc::as_ptr(&other.0) as *const (),
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
trait Bounds: Layout + Debug + Sync + Send + 'static {
|
trait Bounds: Layout + Debug + Sync + Send + 'static {
|
||||||
fn as_any(&self) -> &dyn Any;
|
fn as_any(&self) -> &dyn Any;
|
||||||
fn hash64(&self) -> u64;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T> Bounds for T
|
impl<T> Bounds for T
|
||||||
@ -220,21 +207,6 @@ where
|
|||||||
fn as_any(&self) -> &dyn Any {
|
fn as_any(&self) -> &dyn Any {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
fn hash64(&self) -> u64 {
|
|
||||||
// Also hash the TypeId since nodes with different types but
|
|
||||||
// equal data should be different.
|
|
||||||
let mut state = fxhash::FxHasher64::default();
|
|
||||||
self.type_id().hash(&mut state);
|
|
||||||
self.hash(&mut state);
|
|
||||||
state.finish()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Hash for dyn Bounds {
|
|
||||||
fn hash<H: Hasher>(&self, state: &mut H) {
|
|
||||||
state.write_u64(self.hash64());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A layout node that produces an empty frame.
|
/// A layout node that produces an empty frame.
|
||||||
|
12
src/lib.rs
12
src/lib.rs
@ -62,7 +62,6 @@ use crate::export::RenderCache;
|
|||||||
use crate::font::FontStore;
|
use crate::font::FontStore;
|
||||||
use crate::frame::Frame;
|
use crate::frame::Frame;
|
||||||
use crate::image::ImageStore;
|
use crate::image::ImageStore;
|
||||||
#[cfg(feature = "layout-cache")]
|
|
||||||
use crate::layout::{EvictionPolicy, LayoutCache};
|
use crate::layout::{EvictionPolicy, LayoutCache};
|
||||||
use crate::loading::Loader;
|
use crate::loading::Loader;
|
||||||
use crate::source::{SourceId, SourceStore};
|
use crate::source::{SourceId, SourceStore};
|
||||||
@ -78,7 +77,6 @@ pub struct Context {
|
|||||||
/// Stores decoded images.
|
/// Stores decoded images.
|
||||||
pub images: ImageStore,
|
pub images: ImageStore,
|
||||||
/// Caches layouting artifacts.
|
/// Caches layouting artifacts.
|
||||||
#[cfg(feature = "layout-cache")]
|
|
||||||
pub layout_cache: LayoutCache,
|
pub layout_cache: LayoutCache,
|
||||||
/// Caches rendering artifacts.
|
/// Caches rendering artifacts.
|
||||||
pub render_cache: RenderCache,
|
pub render_cache: RenderCache,
|
||||||
@ -120,7 +118,6 @@ impl Context {
|
|||||||
|
|
||||||
/// Garbage-collect caches.
|
/// Garbage-collect caches.
|
||||||
pub fn turnaround(&mut self) {
|
pub fn turnaround(&mut self) {
|
||||||
#[cfg(feature = "layout-cache")]
|
|
||||||
self.layout_cache.turnaround();
|
self.layout_cache.turnaround();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -131,9 +128,7 @@ impl Context {
|
|||||||
pub struct ContextBuilder {
|
pub struct ContextBuilder {
|
||||||
std: Option<Scope>,
|
std: Option<Scope>,
|
||||||
styles: Option<StyleMap>,
|
styles: Option<StyleMap>,
|
||||||
#[cfg(feature = "layout-cache")]
|
|
||||||
policy: EvictionPolicy,
|
policy: EvictionPolicy,
|
||||||
#[cfg(feature = "layout-cache")]
|
|
||||||
max_size: usize,
|
max_size: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -152,7 +147,6 @@ impl ContextBuilder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// The policy for eviction of the layout cache.
|
/// The policy for eviction of the layout cache.
|
||||||
#[cfg(feature = "layout-cache")]
|
|
||||||
pub fn cache_policy(mut self, policy: EvictionPolicy) -> Self {
|
pub fn cache_policy(mut self, policy: EvictionPolicy) -> Self {
|
||||||
self.policy = policy;
|
self.policy = policy;
|
||||||
self
|
self
|
||||||
@ -162,7 +156,6 @@ impl ContextBuilder {
|
|||||||
///
|
///
|
||||||
/// Note that this can be exceeded if more entries are categorized as [must
|
/// Note that this can be exceeded if more entries are categorized as [must
|
||||||
/// keep][crate::layout::PatternProperties::must_keep].
|
/// keep][crate::layout::PatternProperties::must_keep].
|
||||||
#[cfg(feature = "layout-cache")]
|
|
||||||
pub fn cache_max_size(mut self, max_size: usize) -> Self {
|
pub fn cache_max_size(mut self, max_size: usize) -> Self {
|
||||||
self.max_size = max_size;
|
self.max_size = max_size;
|
||||||
self
|
self
|
||||||
@ -176,7 +169,6 @@ impl ContextBuilder {
|
|||||||
fonts: FontStore::new(Arc::clone(&loader)),
|
fonts: FontStore::new(Arc::clone(&loader)),
|
||||||
images: ImageStore::new(Arc::clone(&loader)),
|
images: ImageStore::new(Arc::clone(&loader)),
|
||||||
loader,
|
loader,
|
||||||
#[cfg(feature = "layout-cache")]
|
|
||||||
layout_cache: LayoutCache::new(self.policy, self.max_size),
|
layout_cache: LayoutCache::new(self.policy, self.max_size),
|
||||||
render_cache: RenderCache::new(),
|
render_cache: RenderCache::new(),
|
||||||
std: self.std.unwrap_or_else(library::new),
|
std: self.std.unwrap_or_else(library::new),
|
||||||
@ -190,9 +182,7 @@ impl Default for ContextBuilder {
|
|||||||
Self {
|
Self {
|
||||||
std: None,
|
std: None,
|
||||||
styles: None,
|
styles: None,
|
||||||
#[cfg(feature = "layout-cache")]
|
|
||||||
policy: EvictionPolicy::default(),
|
policy: EvictionPolicy::default(),
|
||||||
#[cfg(feature = "layout-cache")]
|
|
||||||
max_size: 2000,
|
max_size: 2000,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -209,7 +199,6 @@ pub struct Vm<'a> {
|
|||||||
/// Stores decoded images.
|
/// Stores decoded images.
|
||||||
pub images: &'a mut ImageStore,
|
pub images: &'a mut ImageStore,
|
||||||
/// Caches layouting artifacts.
|
/// Caches layouting artifacts.
|
||||||
#[cfg(feature = "layout-cache")]
|
|
||||||
pub layout_cache: &'a mut LayoutCache,
|
pub layout_cache: &'a mut LayoutCache,
|
||||||
/// The default styles.
|
/// The default styles.
|
||||||
pub styles: &'a StyleMap,
|
pub styles: &'a StyleMap,
|
||||||
@ -223,7 +212,6 @@ pub struct Vm<'a> {
|
|||||||
/// rules.
|
/// rules.
|
||||||
pub rules: Vec<TypeId>,
|
pub rules: Vec<TypeId>,
|
||||||
/// How deeply nested the current layout tree position is.
|
/// How deeply nested the current layout tree position is.
|
||||||
#[cfg(feature = "layout-cache")]
|
|
||||||
pub level: usize,
|
pub level: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,15 +1,12 @@
|
|||||||
|
use std::any::Any;
|
||||||
use std::fmt::{self, Debug, Formatter};
|
use std::fmt::{self, Debug, Formatter};
|
||||||
use std::hash::{Hash, Hasher};
|
use std::hash::{Hash, Hasher};
|
||||||
use std::ops::Deref;
|
use std::ops::Deref;
|
||||||
|
|
||||||
#[cfg(feature = "layout-cache")]
|
|
||||||
use std::any::Any;
|
|
||||||
|
|
||||||
/// A wrapper around a type that precomputes its hash.
|
/// A wrapper around a type that precomputes its hash.
|
||||||
#[derive(Copy, Clone)]
|
#[derive(Copy, Clone)]
|
||||||
pub struct Prehashed<T: ?Sized> {
|
pub struct Prehashed<T: ?Sized> {
|
||||||
/// The precomputed hash.
|
/// The precomputed hash.
|
||||||
#[cfg(feature = "layout-cache")]
|
|
||||||
hash: u64,
|
hash: u64,
|
||||||
/// The wrapped item.
|
/// The wrapped item.
|
||||||
item: T,
|
item: T,
|
||||||
@ -19,7 +16,6 @@ impl<T: Hash + 'static> Prehashed<T> {
|
|||||||
/// Compute an item's hash and wrap it.
|
/// Compute an item's hash and wrap it.
|
||||||
pub fn new(item: T) -> Self {
|
pub fn new(item: T) -> Self {
|
||||||
Self {
|
Self {
|
||||||
#[cfg(feature = "layout-cache")]
|
|
||||||
hash: {
|
hash: {
|
||||||
// Also hash the TypeId because the type might be converted
|
// Also hash the TypeId because the type might be converted
|
||||||
// through an unsized coercion.
|
// through an unsized coercion.
|
||||||
@ -52,23 +48,16 @@ impl<T: Debug + ?Sized> Debug for Prehashed<T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: Hash + ?Sized> Hash for Prehashed<T> {
|
impl<T: ?Sized> Hash for Prehashed<T> {
|
||||||
fn hash<H: Hasher>(&self, state: &mut H) {
|
fn hash<H: Hasher>(&self, state: &mut H) {
|
||||||
// Hash the node.
|
|
||||||
#[cfg(feature = "layout-cache")]
|
|
||||||
state.write_u64(self.hash);
|
state.write_u64(self.hash);
|
||||||
#[cfg(not(feature = "layout-cache"))]
|
|
||||||
self.item.hash(state);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: Eq + ?Sized> Eq for Prehashed<T> {}
|
impl<T: Eq + ?Sized> Eq for Prehashed<T> {}
|
||||||
|
|
||||||
impl<T: PartialEq + ?Sized> PartialEq for Prehashed<T> {
|
impl<T: ?Sized> PartialEq for Prehashed<T> {
|
||||||
fn eq(&self, other: &Self) -> bool {
|
fn eq(&self, other: &Self) -> bool {
|
||||||
#[cfg(feature = "layout-cache")]
|
self.hash == other.hash
|
||||||
return self.hash == other.hash;
|
|
||||||
#[cfg(not(feature = "layout-cache"))]
|
|
||||||
self.item.eq(&other.item)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -137,7 +137,8 @@
|
|||||||
#test([a] == [a], true)
|
#test([a] == [a], true)
|
||||||
#test([[a]] == [a], true)
|
#test([[a]] == [a], true)
|
||||||
#test([] == [a], false)
|
#test([] == [a], false)
|
||||||
#test(box[] == box[], false)
|
#test(box[] == box[], true)
|
||||||
|
#test(box[a] == box[], false)
|
||||||
|
|
||||||
---
|
---
|
||||||
// Test comparison operators.
|
// Test comparison operators.
|
||||||
|
@ -1,10 +1,11 @@
|
|||||||
use std::env;
|
use std::env;
|
||||||
use std::ffi::OsStr;
|
use std::ffi::OsStr;
|
||||||
use std::fs;
|
use std::fs::{self, File};
|
||||||
use std::ops::Range;
|
use std::ops::Range;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
use filedescriptor::{FileDescriptor, StdioDescriptor::*};
|
||||||
use tiny_skia as sk;
|
use tiny_skia as sk;
|
||||||
use walkdir::WalkDir;
|
use walkdir::WalkDir;
|
||||||
|
|
||||||
@ -15,17 +16,10 @@ use typst::geom::{Length, RgbaColor};
|
|||||||
use typst::library::{PageNode, TextNode};
|
use typst::library::{PageNode, TextNode};
|
||||||
use typst::loading::FsLoader;
|
use typst::loading::FsLoader;
|
||||||
use typst::parse::Scanner;
|
use typst::parse::Scanner;
|
||||||
use typst::source::SourceFile;
|
use typst::source::{SourceFile, SourceId};
|
||||||
use typst::syntax::Span;
|
use typst::syntax::Span;
|
||||||
use typst::{Context, Vm};
|
use typst::{Context, Vm};
|
||||||
|
|
||||||
#[cfg(feature = "layout-cache")]
|
|
||||||
use {
|
|
||||||
filedescriptor::{FileDescriptor, StdioDescriptor::*},
|
|
||||||
std::fs::File,
|
|
||||||
typst::source::SourceId,
|
|
||||||
};
|
|
||||||
|
|
||||||
const TYP_DIR: &str = "./typ";
|
const TYP_DIR: &str = "./typ";
|
||||||
const REF_DIR: &str = "./ref";
|
const REF_DIR: &str = "./ref";
|
||||||
const PNG_DIR: &str = "./png";
|
const PNG_DIR: &str = "./png";
|
||||||
@ -277,8 +271,7 @@ fn test_part(
|
|||||||
let mut vm = Vm::new(ctx);
|
let mut vm = Vm::new(ctx);
|
||||||
let (frames, mut errors) = match vm.typeset(id) {
|
let (frames, mut errors) = match vm.typeset(id) {
|
||||||
Ok(mut frames) => {
|
Ok(mut frames) => {
|
||||||
#[cfg(feature = "layout-cache")]
|
ok &= test_incremental(ctx, i, id, &frames);
|
||||||
(ok &= test_incremental(ctx, i, id, &frames));
|
|
||||||
|
|
||||||
if !compare_ref {
|
if !compare_ref {
|
||||||
frames.clear();
|
frames.clear();
|
||||||
@ -474,7 +467,6 @@ fn test_reparse(src: &str, i: usize, rng: &mut LinearShift) -> bool {
|
|||||||
ok
|
ok
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "layout-cache")]
|
|
||||||
fn test_incremental(
|
fn test_incremental(
|
||||||
ctx: &mut Context,
|
ctx: &mut Context,
|
||||||
i: usize,
|
i: usize,
|
||||||
@ -591,7 +583,6 @@ fn render_links(
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Disable stdout and stderr during execution of `f`.
|
/// Disable stdout and stderr during execution of `f`.
|
||||||
#[cfg(feature = "layout-cache")]
|
|
||||||
fn silenced<F, T>(f: F) -> T
|
fn silenced<F, T>(f: F) -> T
|
||||||
where
|
where
|
||||||
F: FnOnce() -> T,
|
F: FnOnce() -> T,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user