From 0bfee5b7772338fd39bbf708d3e31ea7bcec859b Mon Sep 17 00:00:00 2001 From: Laurenz Date: Fri, 28 May 2021 12:44:44 +0200 Subject: Refactored loading and cache architecture --- src/eval/value.rs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'src/eval/value.rs') diff --git a/src/eval/value.rs b/src/eval/value.rs index 0d87c28f..d10d734a 100644 --- a/src/eval/value.rs +++ b/src/eval/value.rs @@ -1,15 +1,15 @@ use std::any::Any; use std::cmp::Ordering; -use std::collections::BTreeMap; +use std::collections::{BTreeMap, HashMap}; use std::fmt::{self, Debug, Display, Formatter}; use std::ops::Deref; use std::rc::Rc; -use super::{EvalContext, NodeMap}; +use super::EvalContext; use crate::color::{Color, RgbaColor}; use crate::exec::ExecContext; use crate::geom::{Angle, Length, Linear, Relative}; -use crate::syntax::{Span, Spanned, Tree}; +use crate::syntax::{Node, Span, Spanned, Tree}; /// A computational value. #[derive(Debug, Clone, PartialEq)] @@ -163,6 +163,14 @@ impl PartialEq for TemplateNode { } } +/// A map from nodes to the values they evaluated to. +/// +/// The raw pointers point into the nodes contained in some [`Tree`]. Since the +/// lifetime is erased, the tree could go out of scope while the hash map still +/// lives. Although this could lead to lookup panics, it is not unsafe since the +/// pointers are never dereferenced. +pub type NodeMap = HashMap<*const Node, Value>; + /// A reference-counted dynamic template node that can implement custom /// behaviour. #[derive(Clone)] -- cgit v1.2.3