summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2022-02-18 17:33:13 +0100
committerLaurenz <laurmaedje@gmail.com>2022-02-18 17:33:13 +0100
commit61d1e1a6831113143c5d1e9f8ccf2a86f90f359a (patch)
tree27c85e1ee876941bba558bb187885ccc4a76f87d /src
parente01970b20a058ab1b4ebea916f229c9b706c84e4 (diff)
Remove layout-cache feature
Diffstat (limited to 'src')
-rw-r--r--src/eval/show.rs25
-rw-r--r--src/layout/incremental.rs15
-rw-r--r--src/layout/mod.rs30
-rw-r--r--src/lib.rs12
-rw-r--r--src/util/prehashed.rs19
5 files changed, 7 insertions, 94 deletions
diff --git a/src/eval/show.rs b/src/eval/show.rs
index a6a48e6f..ac0e2378 100644
--- a/src/eval/show.rs
+++ b/src/eval/show.rs
@@ -1,6 +1,6 @@
use std::any::{Any, TypeId};
use std::fmt::{self, Debug, Formatter};
-use std::hash::{Hash, Hasher};
+use std::hash::Hash;
use std::sync::Arc;
use super::{StyleChain, Template};
@@ -59,18 +59,12 @@ impl Debug for ShowNode {
impl PartialEq for ShowNode {
fn eq(&self, other: &Self) -> bool {
- // We cast to thin pointers for comparison because we don't want to
- // 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 (),
- )
+ self.0.eq(&other.0)
}
}
trait Bounds: Show + Debug + Sync + Send + 'static {
fn as_any(&self) -> &dyn Any;
- fn hash64(&self) -> u64;
}
impl<T> Bounds for T
@@ -80,19 +74,4 @@ where
fn as_any(&self) -> &dyn Any {
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());
- }
}
diff --git a/src/layout/incremental.rs b/src/layout/incremental.rs
index 2112fef1..b68ddcdc 100644
--- a/src/layout/incremental.rs
+++ b/src/layout/incremental.rs
@@ -11,8 +11,6 @@ use crate::geom::Scalar;
const TEMP_LEN: usize = 4;
/// Caches layouting artifacts.
-///
-/// _This is only available when the `layout-cache` feature is enabled._
#[derive(Default, Clone)]
pub struct LayoutCache {
/// 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);
}
}
- #[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 => {
let kept = self.entries().filter(|f| f.properties().must_keep()).count();
@@ -188,8 +178,6 @@ impl LayoutCache {
}
/// Cached frames from past layouting.
-///
-/// _This is only available when the `layout-cache` feature is enabled._
#[derive(Debug, Clone)]
pub struct FramesEntry {
/// The cached frames for a node.
@@ -340,9 +328,6 @@ pub enum EvictionPolicy {
LeastRecentlyUsed,
/// Evict the least frequently used item.
LeastFrequentlyUsed,
- /// Evict randomly.
- #[cfg(feature = "rand")]
- Random,
/// Use the pattern verdicts.
Patterns,
/// Do not evict.
diff --git a/src/layout/mod.rs b/src/layout/mod.rs
index 0d1836fd..afb2621b 100644
--- a/src/layout/mod.rs
+++ b/src/layout/mod.rs
@@ -1,12 +1,10 @@
//! Layouting infrastructure.
mod constraints;
-#[cfg(feature = "layout-cache")]
mod incremental;
mod regions;
pub use constraints::*;
-#[cfg(feature = "layout-cache")]
pub use incremental::*;
pub use regions::*;
@@ -141,10 +139,6 @@ impl Layout for LayoutNode {
) -> TypResult<Vec<Constrained<Arc<Frame>>>> {
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 mut state = fxhash::FxHasher64::default();
self.hash(&mut state);
@@ -154,7 +148,6 @@ impl Layout for LayoutNode {
// This is not written with `unwrap_or_else`, because then the
// #[track_caller] annotation doesn't work.
- #[cfg(feature = "layout-cache")]
if let Some(frames) = vm.layout_cache.get(hash, regions) {
Ok(frames)
} else {
@@ -199,18 +192,12 @@ impl Debug for LayoutNode {
impl PartialEq for LayoutNode {
fn eq(&self, other: &Self) -> bool {
- // We cast to thin pointers for comparison because we don't want to
- // 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 (),
- )
+ self.0.eq(&other.0)
}
}
trait Bounds: Layout + Debug + Sync + Send + 'static {
fn as_any(&self) -> &dyn Any;
- fn hash64(&self) -> u64;
}
impl<T> Bounds for T
@@ -220,21 +207,6 @@ where
fn as_any(&self) -> &dyn Any {
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.
diff --git a/src/lib.rs b/src/lib.rs
index be1bab0d..13c63885 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -62,7 +62,6 @@ use crate::export::RenderCache;
use crate::font::FontStore;
use crate::frame::Frame;
use crate::image::ImageStore;
-#[cfg(feature = "layout-cache")]
use crate::layout::{EvictionPolicy, LayoutCache};
use crate::loading::Loader;
use crate::source::{SourceId, SourceStore};
@@ -78,7 +77,6 @@ pub struct Context {
/// Stores decoded images.
pub images: ImageStore,
/// Caches layouting artifacts.
- #[cfg(feature = "layout-cache")]
pub layout_cache: LayoutCache,
/// Caches rendering artifacts.
pub render_cache: RenderCache,
@@ -120,7 +118,6 @@ impl Context {
/// Garbage-collect caches.
pub fn turnaround(&mut self) {
- #[cfg(feature = "layout-cache")]
self.layout_cache.turnaround();
}
}
@@ -131,9 +128,7 @@ impl Context {
pub struct ContextBuilder {
std: Option<Scope>,
styles: Option<StyleMap>,
- #[cfg(feature = "layout-cache")]
policy: EvictionPolicy,
- #[cfg(feature = "layout-cache")]
max_size: usize,
}
@@ -152,7 +147,6 @@ impl ContextBuilder {
}
/// The policy for eviction of the layout cache.
- #[cfg(feature = "layout-cache")]
pub fn cache_policy(mut self, policy: EvictionPolicy) -> Self {
self.policy = policy;
self
@@ -162,7 +156,6 @@ impl ContextBuilder {
///
/// Note that this can be exceeded if more entries are categorized as [must
/// keep][crate::layout::PatternProperties::must_keep].
- #[cfg(feature = "layout-cache")]
pub fn cache_max_size(mut self, max_size: usize) -> Self {
self.max_size = max_size;
self
@@ -176,7 +169,6 @@ impl ContextBuilder {
fonts: FontStore::new(Arc::clone(&loader)),
images: ImageStore::new(Arc::clone(&loader)),
loader,
- #[cfg(feature = "layout-cache")]
layout_cache: LayoutCache::new(self.policy, self.max_size),
render_cache: RenderCache::new(),
std: self.std.unwrap_or_else(library::new),
@@ -190,9 +182,7 @@ impl Default for ContextBuilder {
Self {
std: None,
styles: None,
- #[cfg(feature = "layout-cache")]
policy: EvictionPolicy::default(),
- #[cfg(feature = "layout-cache")]
max_size: 2000,
}
}
@@ -209,7 +199,6 @@ pub struct Vm<'a> {
/// Stores decoded images.
pub images: &'a mut ImageStore,
/// Caches layouting artifacts.
- #[cfg(feature = "layout-cache")]
pub layout_cache: &'a mut LayoutCache,
/// The default styles.
pub styles: &'a StyleMap,
@@ -223,7 +212,6 @@ pub struct Vm<'a> {
/// rules.
pub rules: Vec<TypeId>,
/// How deeply nested the current layout tree position is.
- #[cfg(feature = "layout-cache")]
pub level: usize,
}
diff --git a/src/util/prehashed.rs b/src/util/prehashed.rs
index 866bda5b..79455918 100644
--- a/src/util/prehashed.rs
+++ b/src/util/prehashed.rs
@@ -1,15 +1,12 @@
+use std::any::Any;
use std::fmt::{self, Debug, Formatter};
use std::hash::{Hash, Hasher};
use std::ops::Deref;
-#[cfg(feature = "layout-cache")]
-use std::any::Any;
-
/// A wrapper around a type that precomputes its hash.
#[derive(Copy, Clone)]
pub struct Prehashed<T: ?Sized> {
/// The precomputed hash.
- #[cfg(feature = "layout-cache")]
hash: u64,
/// The wrapped item.
item: T,
@@ -19,7 +16,6 @@ impl<T: Hash + 'static> Prehashed<T> {
/// Compute an item's hash and wrap it.
pub fn new(item: T) -> Self {
Self {
- #[cfg(feature = "layout-cache")]
hash: {
// Also hash the TypeId because the type might be converted
// 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) {
- // Hash the node.
- #[cfg(feature = "layout-cache")]
state.write_u64(self.hash);
- #[cfg(not(feature = "layout-cache"))]
- self.item.hash(state);
}
}
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 {
- #[cfg(feature = "layout-cache")]
- return self.hash == other.hash;
- #[cfg(not(feature = "layout-cache"))]
- self.item.eq(&other.item)
+ self.hash == other.hash
}
}