summaryrefslogtreecommitdiff
path: root/src/structure.rs
diff options
context:
space:
mode:
authorFederico Mena Quintero <federico@gnome.org>2023-02-22 18:24:33 -0600
committerFederico Mena Quintero <federico@gnome.org>2023-02-27 16:44:17 -0600
commit9a76330749f6d6a57d1b935d9a00c806ec8adb05 (patch)
treedc80faf5fe56dd4c147df2759e417b5452af67ce /src/structure.rs
parent9688c442880e848302d1ee32c73c273767539bf5 (diff)
downloadlibrsvg-9a76330749f6d6a57d1b935d9a00c806ec8adb05.tar.gz
Remove ElementInner<T> and replace it with an ElementData enum
We had this structure: enum Element { Circle(Box<ElementInner<Circle>>), // ... all the supported elements } struct ElementInner<T> { // fields to hold element's name, attributes, SpecifiedValues, etc. element_impl: T } However, "impl ElementInner" has a little bunch of methods, which get monomorphized for each supported element type. These methods don't do anything with the "element_impl: T". Instead, we now have this structure: struct Element { // fields to hold element's name, attributes, SpecifiedValues, etc. element_data: ElementData, } enum ElementData { Circle(Box<Circle>), // ... all the supported elements } The Circle inside the Box, and all the other structs for element types, implement ElementTrait which has the ::draw() method. I'm using concrete types inside the boxes, not Box<ElementTrait>, to avoid having to downcast to the concrete type. The only place that dispatches dynamically is ElementData::draw(). The call_inner!() macro goes away, since it doesn't need to delegate things to the ElementInner any more. All the interesting stuff happens directly in struct Element. The rest of the code doesn't need too many changes, since all the borrowing and type checking happens in the NodeBorrow trait - its borrow_element*() methods, and the macros is_element_of_type!() and borrow_element_as!(). Together with the previous commit that simplifies feComponentTransfer, this removes 186912 bytes from the .text section of rsvg-convert (per objdump's numbers). Part-of: <https://gitlab.gnome.org/GNOME/librsvg/-/merge_requests/801>
Diffstat (limited to 'src/structure.rs')
-rw-r--r--src/structure.rs4
1 files changed, 2 insertions, 2 deletions
diff --git a/src/structure.rs b/src/structure.rs
index 88773a41..7fcfb763 100644
--- a/src/structure.rs
+++ b/src/structure.rs
@@ -7,7 +7,7 @@ use crate::bbox::BoundingBox;
use crate::coord_units::CoordUnits;
use crate::document::{AcquiredNodes, NodeId};
use crate::drawing_ctx::{ClipMode, DrawingCtx, ViewParams};
-use crate::element::{set_attribute, Element, ElementTrait};
+use crate::element::{set_attribute, ElementData, ElementTrait};
use crate::error::*;
use crate::href::{is_href, set_href};
use crate::layout::StackingContext;
@@ -578,7 +578,7 @@ impl ElementTrait for Link {
// If this element is inside of <text>, do not draw it.
// The <text> takes care of it.
for an in node.ancestors() {
- if matches!(&*an.borrow_element(), Element::Text(_)) {
+ if matches!(&*an.borrow_element_data(), ElementData::Text(_)) {
return Ok(draw_ctx.empty_bbox());
}
}