Improve rendering efficiency and add caching (#95)

Fixes #84

*Reduce heap allocations
* Add caching for rendering svgs
* Deduplicate UpdateCanvas Responses
This commit is contained in:
TrueDoctor
2021-05-02 21:21:39 +02:00
committed by Keavon Chambers
parent 457c465342
commit fc10575dfa
14 changed files with 123 additions and 73 deletions

View File

@@ -2,6 +2,8 @@ use crate::{DocumentError, LayerId};
use super::{Layer, LayerData, LayerDataTypes};
use std::fmt::Write;
#[derive(Debug, Clone, PartialEq)]
pub struct Folder {
next_assignment_id: LayerId,
@@ -10,12 +12,10 @@ pub struct Folder {
}
impl LayerData for Folder {
fn render(&self) -> String {
self.layers
.iter()
.filter(|layer| layer.visible)
.map(|layer| layer.data.render())
.fold(String::with_capacity(self.layers.len() * 30), |s, n| s + "\n" + &n)
fn render(&mut self, svg: &mut String) {
self.layers.iter_mut().for_each(|layer| {
let _ = writeln!(svg, "{}", layer.render());
});
}
}
impl Folder {