[librsvg/rustification] Register newly-created nodes in the defs as soon as possible
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg/rustification] Register newly-created nodes in the defs as soon as possible
- Date: Wed, 9 Nov 2016 23:43:48 +0000 (UTC)
commit c8b08f1d0dfc3b5f21482793b9579489796f5a84
Author: Federico Mena Quintero <federico gnome org>
Date: Wed Nov 9 13:47:54 2016 -0600
Register newly-created nodes in the defs as soon as possible
Don't defer it until each node's implementation of ::set_atts().
This reduces the amount of duplicated code in each implementation of
::set_atts().
rsvg-base.c | 17 ++++++++++++++++-
rsvg-filter.c | 42 ++----------------------------------------
rsvg-image.c | 5 ++---
rsvg-marker.c | 4 +---
rsvg-mask.c | 10 ++++------
rsvg-paint-server.c | 6 ------
rsvg-shapes.c | 24 ++++++------------------
rsvg-structure.c | 18 ++++++------------
rsvg-text.c | 10 ++--------
9 files changed, 39 insertions(+), 97 deletions(-)
---
diff --git a/rsvg-base.c b/rsvg-base.c
index ece77cc..bc4d22f 100644
--- a/rsvg-base.c
+++ b/rsvg-base.c
@@ -188,6 +188,19 @@ rsvg_start_style (RsvgHandle * ctx, RsvgPropertyBag *atts)
ctx->priv->handler = &handler->super;
}
+static void
+register_node_in_defs (RsvgHandle *ctx, RsvgNode *node, RsvgPropertyBag *atts)
+{
+ const char *id;
+
+ id = rsvg_property_bag_lookup (atts, "id");
+ if (id) {
+ rsvg_defs_register_node_by_id (ctx->priv->defs, id, node);
+ }
+
+ rsvg_defs_register_memory (ctx->priv->defs, node);
+}
+
static void
rsvg_standard_element_start (RsvgHandle * ctx, const char *name, RsvgPropertyBag * atts)
@@ -313,8 +326,10 @@ rsvg_standard_element_start (RsvgHandle * ctx, const char *name, RsvgPropertyBag
g_assert (RSVG_NODE_TYPE (newnode) != RSVG_NODE_TYPE_INVALID);
newnode->name = (char *) name; /* libxml will keep this while parsing */
newnode->parent = ctx->priv->currentnode;
+
+ register_node_in_defs (ctx, newnode, atts);
rsvg_node_set_atts (newnode, ctx, atts);
- rsvg_defs_register_memory (ctx->priv->defs, newnode);
+
if (ctx->priv->currentnode) {
rsvg_node_group_pack (ctx->priv->currentnode, newnode);
ctx->priv->currentnode = newnode;
diff --git a/rsvg-filter.c b/rsvg-filter.c
index e4b67c8..5fcc079 100644
--- a/rsvg-filter.c
+++ b/rsvg-filter.c
@@ -798,8 +798,6 @@ rsvg_filter_set_atts (RsvgNode * self, RsvgHandle * ctx, RsvgPropertyBag * atts)
filter->width = _rsvg_css_parse_length (value, LENGTH_DIR_HORIZONTAL);
if ((value = rsvg_property_bag_lookup (atts, "height")))
filter->height = _rsvg_css_parse_length (value, LENGTH_DIR_VERTICAL);
- if ((value = rsvg_property_bag_lookup (atts, "id")))
- rsvg_defs_register_node_by_id (ctx->priv->defs, value, self);
}
}
@@ -1039,9 +1037,6 @@ rsvg_filter_primitive_blend_set_atts (RsvgNode * node, RsvgHandle * ctx, RsvgPro
g_string_assign (filter->super.result, value);
filter_primitive_set_x_y_width_height_atts ((RsvgFilterPrimitive *) filter, atts);
-
- if ((value = rsvg_property_bag_lookup (atts, "id")))
- rsvg_defs_register_node_by_id (ctx->priv->defs, value, node);
}
}
@@ -1276,8 +1271,6 @@ rsvg_filter_primitive_convolve_matrix_set_atts (RsvgNode * self,
else
filter->edgemode = 0;
}
- if ((value = rsvg_property_bag_lookup (atts, "id")))
- rsvg_defs_register_node_by_id (ctx->priv->defs, value, self);
}
if ((gint64) listlen != (gint64) filter->orderx * filter->ordery)
@@ -1945,8 +1938,6 @@ rsvg_filter_primitive_gaussian_blur_set_atts (RsvgNode * self,
if ((value = rsvg_property_bag_lookup (atts, "stdDeviation")))
rsvg_css_parse_number_optional_number (value, &filter->sdx, &filter->sdy);
- if ((value = rsvg_property_bag_lookup (atts, "id")))
- rsvg_defs_register_node_by_id (ctx->priv->defs, value, self);
}
}
@@ -2069,8 +2060,6 @@ rsvg_filter_primitive_offset_set_atts (RsvgNode * self, RsvgHandle * ctx, RsvgPr
filter->dx = _rsvg_css_parse_length (value, LENGTH_DIR_HORIZONTAL);
if ((value = rsvg_property_bag_lookup (atts, "dy")))
filter->dy = _rsvg_css_parse_length (value, LENGTH_DIR_VERTICAL);
- if ((value = rsvg_property_bag_lookup (atts, "id")))
- rsvg_defs_register_node_by_id (ctx->priv->defs, value, self);
}
}
@@ -2160,9 +2149,6 @@ rsvg_filter_primitive_merge_set_atts (RsvgNode * self, RsvgHandle * ctx, RsvgPro
g_string_assign (filter->super.result, value);
filter_primitive_set_x_y_width_height_atts ((RsvgFilterPrimitive *) filter, atts);
-
- if ((value = rsvg_property_bag_lookup (atts, "id")))
- rsvg_defs_register_node_by_id (ctx->priv->defs, value, self);
}
}
@@ -2380,8 +2366,6 @@ rsvg_filter_primitive_color_matrix_set_atts (RsvgNode * self, RsvgHandle * ctx,
else
type = 0;
}
- if ((value = rsvg_property_bag_lookup (atts, "id")))
- rsvg_defs_register_node_by_id (ctx->priv->defs, value, self);
}
if (type == 0) {
@@ -2668,9 +2652,6 @@ rsvg_filter_primitive_component_transfer_set_atts (RsvgNode * self, RsvgHandle *
g_string_assign (filter->super.in, value);
filter_primitive_set_x_y_width_height_atts ((RsvgFilterPrimitive *) filter, atts);
-
- if ((value = rsvg_property_bag_lookup (atts, "id")))
- rsvg_defs_register_node_by_id (ctx->priv->defs, value, self);
}
}
@@ -2879,8 +2860,6 @@ rsvg_filter_primitive_erode_set_atts (RsvgNode * self, RsvgHandle * ctx, RsvgPro
else if (!strcmp (value, "dilate"))
filter->mode = 1;
}
- if ((value = rsvg_property_bag_lookup (atts, "id")))
- rsvg_defs_register_node_by_id (ctx->priv->defs, value, self);
}
}
@@ -3114,8 +3093,6 @@ rsvg_filter_primitive_composite_set_atts (RsvgNode * self, RsvgHandle * ctx, Rsv
filter->k3 = g_ascii_strtod (value, NULL) * 255.;
if ((value = rsvg_property_bag_lookup (atts, "k4")))
filter->k4 = g_ascii_strtod (value, NULL) * 255.;
- if ((value = rsvg_property_bag_lookup (atts, "id")))
- rsvg_defs_register_node_by_id (ctx->priv->defs, value, self);
}
}
@@ -3201,10 +3178,9 @@ rsvg_filter_primitive_flood_set_atts (RsvgNode * self, RsvgHandle * ctx, RsvgPro
filter_primitive_set_x_y_width_height_atts ((RsvgFilterPrimitive *) filter, atts);
- if ((value = rsvg_property_bag_lookup (atts, "id"))) {
+ if ((value = rsvg_property_bag_lookup (atts, "id")))
id = value;
- rsvg_defs_register_node_by_id (ctx->priv->defs, value, self);
- }
+
rsvg_parse_style_attrs (ctx, self->state, "feFlood", NULL, id, atts);
}
}
@@ -3391,8 +3367,6 @@ rsvg_filter_primitive_displacement_map_set_atts (RsvgNode * self, RsvgHandle * c
filter->yChannelSelector = (value)[0];
if ((value = rsvg_property_bag_lookup (atts, "scale")))
filter->scale = g_ascii_strtod (value, NULL);
- if ((value = rsvg_property_bag_lookup (atts, "id")))
- rsvg_defs_register_node_by_id (ctx->priv->defs, value, self);
}
}
@@ -3757,8 +3731,6 @@ rsvg_filter_primitive_turbulence_set_atts (RsvgNode * self, RsvgHandle * ctx,
filter->bDoStitching = (!strcmp (value, "stitch"));
if ((value = rsvg_property_bag_lookup (atts, "type")))
filter->bFractalSum = (!strcmp (value, "fractalNoise"));
- if ((value = rsvg_property_bag_lookup (atts, "id")))
- rsvg_defs_register_node_by_id (ctx->priv->defs, value, self);
}
}
@@ -3978,9 +3950,6 @@ rsvg_filter_primitive_image_set_atts (RsvgNode * self, RsvgHandle * ctx, RsvgPro
}
filter_primitive_set_x_y_width_height_atts ((RsvgFilterPrimitive *) filter, atts);
-
- if ((value = rsvg_property_bag_lookup (atts, "id")))
- rsvg_defs_register_node_by_id (ctx->priv->defs, value, self);
}
}
@@ -4546,8 +4515,6 @@ rsvg_filter_primitive_diffuse_lighting_set_atts (RsvgNode * self, RsvgHandle * c
filter->diffuseConstant = g_ascii_strtod (value, NULL);
if ((value = rsvg_property_bag_lookup (atts, "surfaceScale")))
filter->surfaceScale = g_ascii_strtod (value, NULL);
- if ((value = rsvg_property_bag_lookup (atts, "id")))
- rsvg_defs_register_node_by_id (ctx->priv->defs, value, self);
}
}
@@ -4718,8 +4685,6 @@ rsvg_filter_primitive_specular_lighting_set_atts (RsvgNode * self, RsvgHandle *
filter->specularExponent = g_ascii_strtod (value, NULL);
if ((value = rsvg_property_bag_lookup (atts, "surfaceScale")))
filter->surfaceScale = g_ascii_strtod (value, NULL);
- if ((value = rsvg_property_bag_lookup (atts, "id")))
- rsvg_defs_register_node_by_id (ctx->priv->defs, value, self);
}
}
@@ -4827,9 +4792,6 @@ rsvg_filter_primitive_tile_set_atts (RsvgNode * self, RsvgHandle * ctx, RsvgProp
g_string_assign (filter->super.result, value);
filter_primitive_set_x_y_width_height_atts ((RsvgFilterPrimitive *) filter, atts);
-
- if ((value = rsvg_property_bag_lookup (atts, "id")))
- rsvg_defs_register_node_by_id (ctx->priv->defs, value, self);
}
}
diff --git a/rsvg-image.c b/rsvg-image.c
index d8912c7..700aa79 100644
--- a/rsvg-image.c
+++ b/rsvg-image.c
@@ -227,10 +227,9 @@ rsvg_node_image_set_atts (RsvgNode * self, RsvgHandle * ctx, RsvgPropertyBag * a
}
if ((value = rsvg_property_bag_lookup (atts, "class")))
klazz = value;
- if ((value = rsvg_property_bag_lookup (atts, "id"))) {
+ if ((value = rsvg_property_bag_lookup (atts, "id")))
id = value;
- rsvg_defs_register_node_by_id (ctx->priv->defs, id, self);
- }
+
if ((value = rsvg_property_bag_lookup (atts, "preserveAspectRatio")))
image->preserve_aspect_ratio = rsvg_css_parse_aspect_ratio (value);
diff --git a/rsvg-marker.c b/rsvg-marker.c
index 28b9a06..8d333df 100644
--- a/rsvg-marker.c
+++ b/rsvg-marker.c
@@ -60,10 +60,8 @@ rsvg_node_marker_set_atts (RsvgNode * self, RsvgHandle * ctx, RsvgPropertyBag *
marker = (RsvgMarker *) self;
if (rsvg_property_bag_size (atts)) {
- if ((value = rsvg_property_bag_lookup (atts, "id"))) {
+ if ((value = rsvg_property_bag_lookup (atts, "id")))
id = value;
- rsvg_defs_register_node_by_id (ctx->priv->defs, id, self);
- }
if ((value = rsvg_property_bag_lookup (atts, "class")))
klazz = value;
if ((value = rsvg_property_bag_lookup (atts, "viewBox")))
diff --git a/rsvg-mask.c b/rsvg-mask.c
index ea2475b..90ccd76 100644
--- a/rsvg-mask.c
+++ b/rsvg-mask.c
@@ -57,10 +57,9 @@ rsvg_mask_set_atts (RsvgNode * self, RsvgHandle * ctx, RsvgPropertyBag * atts)
mask->width = _rsvg_css_parse_length (value, LENGTH_DIR_HORIZONTAL);
if ((value = rsvg_property_bag_lookup (atts, "height")))
mask->height = _rsvg_css_parse_length (value, LENGTH_DIR_VERTICAL);
- if ((value = rsvg_property_bag_lookup (atts, "id"))) {
+ if ((value = rsvg_property_bag_lookup (atts, "id")))
id = value;
- rsvg_defs_register_node_by_id (ctx->priv->defs, id, self);
- }
+
if ((value = rsvg_property_bag_lookup (atts, "class")))
klazz = value;
}
@@ -117,10 +116,9 @@ rsvg_clip_path_set_atts (RsvgNode * self, RsvgHandle * ctx, RsvgPropertyBag * at
else
clip_path->units = userSpaceOnUse;
}
- if ((value = rsvg_property_bag_lookup (atts, "id"))) {
+ if ((value = rsvg_property_bag_lookup (atts, "id")))
id = value;
- rsvg_defs_register_node_by_id (ctx->priv->defs, id, self);
- }
+
if ((value = rsvg_property_bag_lookup (atts, "class")))
klazz = value;
}
diff --git a/rsvg-paint-server.c b/rsvg-paint-server.c
index 5c97627..1bbb4cb 100644
--- a/rsvg-paint-server.c
+++ b/rsvg-paint-server.c
@@ -205,8 +205,6 @@ rsvg_linear_gradient_set_atts (RsvgNode * self, RsvgHandle * ctx, RsvgPropertyBa
const char *value;
if (rsvg_property_bag_size (atts)) {
- if ((value = rsvg_property_bag_lookup (atts, "id")))
- rsvg_defs_register_node_by_id (ctx->priv->defs, value, self);
if ((value = rsvg_property_bag_lookup (atts, "x1"))) {
grad->x1 = _rsvg_css_parse_length (value, LENGTH_DIR_HORIZONTAL);
grad->hasx1 = TRUE;
@@ -288,8 +286,6 @@ rsvg_radial_gradient_set_atts (RsvgNode * self, RsvgHandle * ctx, RsvgPropertyBa
const char *value;
if (rsvg_property_bag_size (atts)) {
- if ((value = rsvg_property_bag_lookup (atts, "id")))
- rsvg_defs_register_node_by_id (ctx->priv->defs, value, self);
if ((value = rsvg_property_bag_lookup (atts, "cx"))) {
grad->cx = _rsvg_css_parse_length (value, LENGTH_DIR_HORIZONTAL);
grad->hascx = TRUE;
@@ -377,8 +373,6 @@ rsvg_pattern_set_atts (RsvgNode * self, RsvgHandle * ctx, RsvgPropertyBag * atts
const char *value;
if (rsvg_property_bag_size (atts)) {
- if ((value = rsvg_property_bag_lookup (atts, "id")))
- rsvg_defs_register_node_by_id (ctx->priv->defs, value, self);
if ((value = rsvg_property_bag_lookup (atts, "viewBox"))) {
pattern->vbox = rsvg_css_parse_vbox (value);
pattern->hasvbox = TRUE;
diff --git a/rsvg-shapes.c b/rsvg-shapes.c
index 01dbf9b..6c46798 100644
--- a/rsvg-shapes.c
+++ b/rsvg-shapes.c
@@ -84,10 +84,8 @@ rsvg_node_path_set_atts (RsvgNode * self, RsvgHandle * ctx, RsvgPropertyBag * at
}
if ((value = rsvg_property_bag_lookup (atts, "class")))
klazz = value;
- if ((value = rsvg_property_bag_lookup (atts, "id"))) {
+ if ((value = rsvg_property_bag_lookup (atts, "id")))
id = value;
- rsvg_defs_register_node_by_id (ctx->priv->defs, value, self);
- }
rsvg_parse_style_attrs (ctx, self->state, "path", klazz, id, atts);
}
@@ -135,10 +133,8 @@ _rsvg_node_poly_set_atts (RsvgNode * self, RsvgHandle * ctx, RsvgPropertyBag * a
}
if ((value = rsvg_property_bag_lookup (atts, "class")))
klazz = value;
- if ((value = rsvg_property_bag_lookup (atts, "id"))) {
+ if ((value = rsvg_property_bag_lookup (atts, "id")))
id = value;
- rsvg_defs_register_node_by_id (ctx->priv->defs, id, self);
- }
rsvg_parse_style_attrs (ctx, self->state,
RSVG_NODE_TYPE (self) == RSVG_NODE_TYPE_POLYLINE ? "polyline" : "polygon",
@@ -266,10 +262,8 @@ _rsvg_node_line_set_atts (RsvgNode * self, RsvgHandle * ctx, RsvgPropertyBag * a
line->y2 = _rsvg_css_parse_length (value, LENGTH_DIR_VERTICAL);
if ((value = rsvg_property_bag_lookup (atts, "class")))
klazz = value;
- if ((value = rsvg_property_bag_lookup (atts, "id"))) {
+ if ((value = rsvg_property_bag_lookup (atts, "id")))
id = value;
- rsvg_defs_register_node_by_id (ctx->priv->defs, id, self);
- }
rsvg_parse_style_attrs (ctx, self->state, "line", klazz, id, atts);
}
@@ -345,10 +339,8 @@ _rsvg_node_rect_set_atts (RsvgNode * self, RsvgHandle * ctx, RsvgPropertyBag * a
}
if ((value = rsvg_property_bag_lookup (atts, "class")))
klazz = value;
- if ((value = rsvg_property_bag_lookup (atts, "id"))) {
+ if ((value = rsvg_property_bag_lookup (atts, "id")))
id = value;
- rsvg_defs_register_node_by_id (ctx->priv->defs, id, self);
- }
rsvg_parse_style_attrs (ctx, self->state, "rect", klazz, id, atts);
}
@@ -528,10 +520,8 @@ _rsvg_node_circle_set_atts (RsvgNode * self, RsvgHandle * ctx, RsvgPropertyBag *
circle->r = _rsvg_css_parse_length (value, LENGTH_DIR_BOTH);
if ((value = rsvg_property_bag_lookup (atts, "class")))
klazz = value;
- if ((value = rsvg_property_bag_lookup (atts, "id"))) {
+ if ((value = rsvg_property_bag_lookup (atts, "id")))
id = value;
- rsvg_defs_register_node_by_id (ctx->priv->defs, id, self);
- }
rsvg_parse_style_attrs (ctx, self->state, "circle", klazz, id, atts);
}
@@ -622,10 +612,8 @@ _rsvg_node_ellipse_set_atts (RsvgNode * self, RsvgHandle * ctx, RsvgPropertyBag
ellipse->ry = _rsvg_css_parse_length (value, LENGTH_DIR_VERTICAL);
if ((value = rsvg_property_bag_lookup (atts, "class")))
klazz = value;
- if ((value = rsvg_property_bag_lookup (atts, "id"))) {
+ if ((value = rsvg_property_bag_lookup (atts, "id")))
id = value;
- rsvg_defs_register_node_by_id (ctx->priv->defs, id, self);
- }
rsvg_parse_style_attrs (ctx, self->state, "ellipse", klazz, id, atts);
}
diff --git a/rsvg-structure.c b/rsvg-structure.c
index 8b5daa2..c494cf5 100644
--- a/rsvg-structure.c
+++ b/rsvg-structure.c
@@ -125,10 +125,8 @@ rsvg_node_group_set_atts (RsvgNode * self, RsvgHandle * ctx, RsvgPropertyBag * a
if (rsvg_property_bag_size (atts)) {
if ((value = rsvg_property_bag_lookup (atts, "class")))
klazz = value;
- if ((value = rsvg_property_bag_lookup (atts, "id"))) {
+ if ((value = rsvg_property_bag_lookup (atts, "id")))
id = value;
- rsvg_defs_register_node_by_id (ctx->priv->defs, id, self);
- }
rsvg_parse_style_attrs (ctx, self->state, "g", klazz, id, atts);
}
@@ -331,9 +329,7 @@ rsvg_node_svg_set_atts (RsvgNode * self, RsvgHandle * ctx, RsvgPropertyBag * att
svg->x = _rsvg_css_parse_length (value, LENGTH_DIR_HORIZONTAL);
if (self->parent && (value = rsvg_property_bag_lookup (atts, "y")))
svg->y = _rsvg_css_parse_length (value, LENGTH_DIR_VERTICAL);
- if ((value = rsvg_property_bag_lookup (atts, "id"))) {
- rsvg_defs_register_node_by_id (ctx->priv->defs, value, self);
- }
+
/*
* style element is not loaded yet here, so we need to store those attribues
* to be applied later.
@@ -413,10 +409,9 @@ rsvg_node_use_set_atts (RsvgNode * self, RsvgHandle * ctx, RsvgPropertyBag * att
use->h = _rsvg_css_parse_length (value, LENGTH_DIR_VERTICAL);
if ((value = rsvg_property_bag_lookup (atts, "class")))
klazz = value;
- if ((value = rsvg_property_bag_lookup (atts, "id"))) {
+ if ((value = rsvg_property_bag_lookup (atts, "id")))
id = value;
- rsvg_defs_register_node_by_id (ctx->priv->defs, id, self);
- }
+
if ((value = rsvg_property_bag_lookup (atts, "xlink:href"))) {
g_free (use->link);
use->link = g_strdup (value);
@@ -453,10 +448,9 @@ rsvg_node_symbol_set_atts (RsvgNode * self, RsvgHandle * ctx, RsvgPropertyBag *
if (rsvg_property_bag_size (atts)) {
if ((value = rsvg_property_bag_lookup (atts, "class")))
klazz = value;
- if ((value = rsvg_property_bag_lookup (atts, "id"))) {
+ if ((value = rsvg_property_bag_lookup (atts, "id")))
id = value;
- rsvg_defs_register_node_by_id (ctx->priv->defs, id, self);
- }
+
if ((value = rsvg_property_bag_lookup (atts, "viewBox")))
symbol->vbox = rsvg_css_parse_vbox (value);
if ((value = rsvg_property_bag_lookup (atts, "preserveAspectRatio")))
diff --git a/rsvg-text.c b/rsvg-text.c
index bd0cbe0..45ad3f3 100644
--- a/rsvg-text.c
+++ b/rsvg-text.c
@@ -156,10 +156,8 @@ _rsvg_node_text_set_atts (RsvgNode * self, RsvgHandle * ctx, RsvgPropertyBag * a
if ((value = rsvg_property_bag_lookup (atts, "class")))
klazz = value;
- if ((value = rsvg_property_bag_lookup (atts, "id"))) {
+ if ((value = rsvg_property_bag_lookup (atts, "id")))
id = value;
- rsvg_defs_register_node_by_id (ctx->priv->defs, id, self);
- }
rsvg_parse_style_attrs (ctx, self->state, "text", klazz, id, atts);
}
@@ -400,10 +398,8 @@ _rsvg_node_tspan_set_atts (RsvgNode * self, RsvgHandle * ctx, RsvgPropertyBag *
if ((value = rsvg_property_bag_lookup (atts, "class")))
klazz = value;
- if ((value = rsvg_property_bag_lookup (atts, "id"))) {
+ if ((value = rsvg_property_bag_lookup (atts, "id")))
id = value;
- rsvg_defs_register_node_by_id (ctx->priv->defs, id, self);
- }
rsvg_parse_style_attrs (ctx, self->state, "tspan", klazz, id, atts);
}
@@ -478,8 +474,6 @@ _rsvg_node_tref_set_atts (RsvgNode * self, RsvgHandle * ctx, RsvgPropertyBag * a
g_free (text->link);
text->link = g_strdup (value);
}
- if ((value = rsvg_property_bag_lookup (atts, "id")))
- rsvg_defs_register_node_by_id (ctx->priv->defs, value, self);
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]