[librsvg: 1/2] Box a big variant in CascadedValues to use less stack space
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg: 1/2] Box a big variant in CascadedValues to use less stack space
- Date: Mon, 1 Mar 2021 19:21:56 +0000 (UTC)
commit e500e03a054a853fd6befd00b27b720b7a6d3171
Author: Federico Mena Quintero <federico gnome org>
Date: Thu Feb 25 17:52:22 2021 -0600
Box a big variant in CascadedValues to use less stack space
CascadedInner has two variants, and the second is a big struct:
#[allow(clippy::large_enum_variant)]
enum CascadedInner<'a> {
FromNode(Ref<'a, Element>),
FromValues(ComputedValues),
}
(Yes, clippy warned us...)
It turns out that deeply-nested <use> elements can consume a lot of
stack space, since every nested call to
DrawingCtx::draw_from_use_node() will create a
CascadedInner::FromValues - it is specifically to handle the
independent cascading of nodes referenced from <use>.
This commit just boxes the payload of that variant, so it should
shrink the stack space of draw_from_use_node() by approximately 700
bytes.
Old size_of::<CascadedValues<'_>>() = 776
New size_of::<CascadedValues<'_>>() = 24 (plus the rest in the heap)
https://gitlab.gnome.org/GNOME/librsvg/-/issues/686
src/node.rs | 9 ++++-----
1 file changed, 4 insertions(+), 5 deletions(-)
---
diff --git a/src/node.rs b/src/node.rs
index 5c9ddef2..862d2328 100644
--- a/src/node.rs
+++ b/src/node.rs
@@ -106,10 +106,9 @@ pub struct CascadedValues<'a> {
inner: CascadedInner<'a>,
}
-#[allow(clippy::large_enum_variant)]
enum CascadedInner<'a> {
FromNode(Ref<'a, Element>),
- FromValues(ComputedValues),
+ FromValues(Box<ComputedValues>),
}
impl<'a> CascadedValues<'a> {
@@ -124,7 +123,7 @@ impl<'a> CascadedValues<'a> {
inner: CascadedInner::FromNode(node.borrow_element()),
},
- CascadedInner::FromValues(ref v) => CascadedValues::new_from_values(node, v),
+ CascadedInner::FromValues(ref v) => CascadedValues::new_from_values(node, &*v),
}
}
@@ -145,7 +144,7 @@ impl<'a> CascadedValues<'a> {
/// This is for the `<use>` element, which draws the element which it references with the
/// `<use>`'s own cascade, not with the element's original cascade.
pub fn new_from_values(node: &'a Node, values: &ComputedValues) -> CascadedValues<'a> {
- let mut v = values.clone();
+ let mut v = Box::new(values.clone());
node.borrow_element()
.get_specified_values()
.to_computed_values(&mut v);
@@ -162,7 +161,7 @@ impl<'a> CascadedValues<'a> {
pub fn get(&'a self) -> &'a ComputedValues {
match self.inner {
CascadedInner::FromNode(ref e) => e.get_computed_values(),
- CascadedInner::FromValues(ref v) => v,
+ CascadedInner::FromValues(ref v) => &*v,
}
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]